C#用HttpClient抓取jd.com搜索框下拉数据

添加System.Web.dll引用
添加System.Net.Http引用

using System.Net.Http;
using System.Web;

string key = "电脑"; //拼音diannao也可
string url = string.Format("http://dd.search.jd.com/?ver=2&zip=1&key={0}&t={1}", HttpUtility.UrlPathEncode(key), DateTime.Now.Millisecond);
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Referrer = new Uri("http://www.jd.com/"); //这个比较重要
string result = httpClient.GetStringAsync(url).Result;
Console.WriteLine(result);
posted @ 2015-08-19 21:09  liqipeng  阅读(417)  评论(0编辑  收藏  举报