0
我一直試圖通過代理使用htmlagilitypack,我發現我得到了一些不可預知的行爲。代理和htmlagilitypack問題
如何向htmlagilitypack添加憑證,以便它能夠通過代理來抓取網頁?
我一直試圖通過代理使用htmlagilitypack,我發現我得到了一些不可預知的行爲。代理和htmlagilitypack問題
如何向htmlagilitypack添加憑證,以便它能夠通過代理來抓取網頁?
這是我平時做:
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(url);
...
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) {
var doc = new HtmlDocument();
doc.Load(reader.BaseStream);
//Use (or return) the HtmlDocument 'doc' here.
}
您可以封裝在一個方法給定一個URL這個代碼,返回一個HtmlDocument
對象。
這裏有enter link description here
已經回答了你在你的代碼,如下使用了類似的問題。
HtmlWeb web = new HtmlWeb();
web.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6";
var doc = web.Load(string url, string proxyHost, int proxyPort, string yourUserId, string yourPassword);
使用'HttpWebRequest'或'WebClient'下載頁面,然後再加載字符串HAP。 – 2012-07-20 16:32:50
這是一個好主意 - 謝謝 – 2012-07-21 03:27:29