private string GetHttpWebRequest(string url)
{
try
{
if (url.IndexOf("http:") == -1)
{
url = "http:" + url;
}
Uri uri = new Uri(url);
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(uri);
myReq.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
myReq.Accept = "*/*";
myReq.KeepAlive = true;
myReq.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
HttpWebResponse result = (HttpWebResponse)myReq.GetResponse();
Stream receviceStream = result.GetResponseStream();
StreamReader readerOfStream = new StreamReader(receviceStream, System.Text.Encoding.GetEncoding("gbk"));
string strHTML = readerOfStream.ReadToEnd();
readerOfStream.Close();
receviceStream.Close();
result.Close();
return strHTML;
}
catch (Exception es)
{
return es.ToString();
}
}
11 个解决方案
#1
把你获取的html和右键查看的html发出来看看
#2
你用fiddler看看网络请求,关键信息可能是通过javascript调用其他页面得到的数据
#3
url 用的是 http://list.tmall.com/search_product.htm?spm=a220m.1000858.1000722.1.5x678O&cat=50031543&brand=59732&prop=413:900000451&sort=d&style=g&search_condition=23&from=sn_1_xuangou-qp&active=1&industryCatId=50029231#J_crumbs
我想要的是
<div class="product" data-id="27144728370"
data-atp="a!,,50011993,,,,,,">
<div class="product-iWrap">
<div class="productImg-wrap">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" class="productImg" target="_blank" data-p="1-10">
<img src= "http://gi3.mlist.alicdn.com/bao/uploaded/i3/TB1c7HwGFXXXXa_XpXXXXXXXXXX_!!0-item_pic.jpg_b.jpg" />
</a>
<a class="j_ProductPin productPin" data-p="1-12"><span>钉一下已钉住</span></a></div>
<p class="productPrice">
<em title="168.00"><b>¥</b>168.00</em>
</p>
<p class="productTitle">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" target="_blank" title="相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿" data-p="1-11" >
相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿
</a>
</p>
<div class="productShop" data-atp="b!1-3,{user_id},,,,,,">
<a class="productShop-name" href="http://store.taobao.com/search.htm?rn=3823164b3c30bf3f75e93f94288dc260&user_number_id=1763879796" target="_blank">
相宜本草故梦专卖店
</a>
</div>
<p class="productStatus">
<span>该款月成交 <em>36笔</em></span>
<span data-icon="small" class="ww-light ww-small m_wangwang J_WangWang" data-item="27144728370" data-nick="相宜本草故梦专卖店" data-tnick="相宜本草故梦专卖店" data-display="inline"
data-atp="a!1-2,,,,,,,1763879796"></span>
</p>
</div>
</div>
这一段代码
可是
strHTML 中没有
我想要的是
<div class="product" data-id="27144728370"
data-atp="a!,,50011993,,,,,,">
<div class="product-iWrap">
<div class="productImg-wrap">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" class="productImg" target="_blank" data-p="1-10">
<img src= "http://gi3.mlist.alicdn.com/bao/uploaded/i3/TB1c7HwGFXXXXa_XpXXXXXXXXXX_!!0-item_pic.jpg_b.jpg" />
</a>
<a class="j_ProductPin productPin" data-p="1-12"><span>钉一下已钉住</span></a></div>
<p class="productPrice">
<em title="168.00"><b>¥</b>168.00</em>
</p>
<p class="productTitle">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" target="_blank" title="相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿" data-p="1-11" >
相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿
</a>
</p>
<div class="productShop" data-atp="b!1-3,{user_id},,,,,,">
<a class="productShop-name" href="http://store.taobao.com/search.htm?rn=3823164b3c30bf3f75e93f94288dc260&user_number_id=1763879796" target="_blank">
相宜本草故梦专卖店
</a>
</div>
<p class="productStatus">
<span>该款月成交 <em>36笔</em></span>
<span data-icon="small" class="ww-light ww-small m_wangwang J_WangWang" data-item="27144728370" data-nick="相宜本草故梦专卖店" data-tnick="相宜本草故梦专卖店" data-display="inline"
data-atp="a!1-2,,,,,,,1763879796"></span>
</p>
</div>
</div>
这一段代码
可是
strHTML 中没有
#4
使用fiddler
把对应的
改成
myReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0";
myReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
myReq.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
之后 还是一样
strHTML 中没有我需要的代码
#5
差cookie,你把本地cookie清掉,再用fiddler,你可以看到,他做了一次Location: https://login.taobao.com/jump?target=的跳转
#6
请教要怎么做才能 解决这个问题 啊 ,请教
#7
用cookiecontainer传cookie
#8
个人水平有限 ,不知道怎么处理 ,版主能 指点下吗,
#9
解决了 谢谢版主
#10
请问你是怎么解决的啊?拜托了!
#11
请问要怎么解决的啊?拜托了!
#1
把你获取的html和右键查看的html发出来看看
#2
你用fiddler看看网络请求,关键信息可能是通过javascript调用其他页面得到的数据
#3
url 用的是 http://list.tmall.com/search_product.htm?spm=a220m.1000858.1000722.1.5x678O&cat=50031543&brand=59732&prop=413:900000451&sort=d&style=g&search_condition=23&from=sn_1_xuangou-qp&active=1&industryCatId=50029231#J_crumbs
我想要的是
<div class="product" data-id="27144728370"
data-atp="a!,,50011993,,,,,,">
<div class="product-iWrap">
<div class="productImg-wrap">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" class="productImg" target="_blank" data-p="1-10">
<img src= "http://gi3.mlist.alicdn.com/bao/uploaded/i3/TB1c7HwGFXXXXa_XpXXXXXXXXXX_!!0-item_pic.jpg_b.jpg" />
</a>
<a class="j_ProductPin productPin" data-p="1-12"><span>钉一下已钉住</span></a></div>
<p class="productPrice">
<em title="168.00"><b>¥</b>168.00</em>
</p>
<p class="productTitle">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" target="_blank" title="相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿" data-p="1-11" >
相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿
</a>
</p>
<div class="productShop" data-atp="b!1-3,{user_id},,,,,,">
<a class="productShop-name" href="http://store.taobao.com/search.htm?rn=3823164b3c30bf3f75e93f94288dc260&user_number_id=1763879796" target="_blank">
相宜本草故梦专卖店
</a>
</div>
<p class="productStatus">
<span>该款月成交 <em>36笔</em></span>
<span data-icon="small" class="ww-light ww-small m_wangwang J_WangWang" data-item="27144728370" data-nick="相宜本草故梦专卖店" data-tnick="相宜本草故梦专卖店" data-display="inline"
data-atp="a!1-2,,,,,,,1763879796"></span>
</p>
</div>
</div>
这一段代码
可是
strHTML 中没有
我想要的是
<div class="product" data-id="27144728370"
data-atp="a!,,50011993,,,,,,">
<div class="product-iWrap">
<div class="productImg-wrap">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" class="productImg" target="_blank" data-p="1-10">
<img src= "http://gi3.mlist.alicdn.com/bao/uploaded/i3/TB1c7HwGFXXXXa_XpXXXXXXXXXX_!!0-item_pic.jpg_b.jpg" />
</a>
<a class="j_ProductPin productPin" data-p="1-12"><span>钉一下已钉住</span></a></div>
<p class="productPrice">
<em title="168.00"><b>¥</b>168.00</em>
</p>
<p class="productTitle">
<a href="//detail.tmall.com/item.htm?id=27144728370&skuId=47865503807&areaId=130100&sku=413:900000451&cat_id=50031543&rn=3823164b3c30bf3f75e93f94288dc260&user_id=1763879796&is_b=1" target="_blank" title="相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿" data-p="1-11" >
相宜本草 芯净自然护肤3件套装 洁面爽肤水乳液 控油清爽保湿
</a>
</p>
<div class="productShop" data-atp="b!1-3,{user_id},,,,,,">
<a class="productShop-name" href="http://store.taobao.com/search.htm?rn=3823164b3c30bf3f75e93f94288dc260&user_number_id=1763879796" target="_blank">
相宜本草故梦专卖店
</a>
</div>
<p class="productStatus">
<span>该款月成交 <em>36笔</em></span>
<span data-icon="small" class="ww-light ww-small m_wangwang J_WangWang" data-item="27144728370" data-nick="相宜本草故梦专卖店" data-tnick="相宜本草故梦专卖店" data-display="inline"
data-atp="a!1-2,,,,,,,1763879796"></span>
</p>
</div>
</div>
这一段代码
可是
strHTML 中没有
#4
使用fiddler
把对应的
改成
myReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0";
myReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
myReq.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
之后 还是一样
strHTML 中没有我需要的代码
#5
差cookie,你把本地cookie清掉,再用fiddler,你可以看到,他做了一次Location: https://login.taobao.com/jump?target=的跳转
#6
请教要怎么做才能 解决这个问题 啊 ,请教
#7
用cookiecontainer传cookie
#8
个人水平有限 ,不知道怎么处理 ,版主能 指点下吗,
#9
解决了 谢谢版主
#10
请问你是怎么解决的啊?拜托了!
#11
请问要怎么解决的啊?拜托了!