我想为受https://www.homedepot.com/等受IP保护的网站加载HTML 在巴基斯坦无法访问此网站。
,我想获取HTML Source。我该怎么办?
我正在尝试下面给出的这段代码。
public HtmlAgilityPack.HtmlDocument LoadHtml(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31";
request.AllowAutoRedirect = false;
HtmlAgilityPack.HtmlDocument htmlDoc = null;
//WebProxy myproxy = new WebProxy("198.12.118.99", 80);
//myproxy.BypassProxyOnLocal = false;
request.AllowAutoRedirect = true;
//myproxy.Credentials = new NetworkCredential("dasani", "amazon1!");
//request.Proxy = myproxy;
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.Load(response.GetResponseStream());
response.Close();
}
catch (WebException ex)
{
ex.ToString();
//MessageBox.Show(ex.ToString());
}
return htmlDoc;
}