.net爬蟲獲取post資料
阿新 • • 發佈:2018-12-09
用Fiddler抓下請求的資訊,在http頭裡面會看到下面的資料: Accept: */* Accept-Encoding: gzip, deflate Accept-Language: zh-CN User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E) 然後照單填進HttpRequest裡就行了:
MyHttpWebRequest.Accept = "*/*"; MyHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); MyHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN"); MyHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
WinForm裡有一個WebBrowse控制元件可以獲取網頁內容
WebBrowser webBrowser =
new
WebBrowser();
Uri url =
new
Uri(
"http://www.amazon.com/gp/offer-listing/B004PLY1EG"
);
webBrowser.Url = url;
webBrowser.DocumentCompleted +=
new
WebBrowserDocumentCompletedEventHandler((sender, e) =>
{
if
(e.Url == url)
{
string
content = ((WebBrowser)sender).DocumentText;
}
});
看明白了嗎