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);
如果你觉得这篇文章对你有帮助或者使你有所启发,请点击右下角的推荐按钮,谢谢,:)