HTML AGILITY PACK:使用Proxies?

html-agility-pack

如何在HAP中使用代理?這就是我到目前為止......(沒有運氣)。

IPCHICKEN只是用來測試IP地址。它顯示我的IP地址,而不是我的代理的IP地址

Function GetPrice(ByVal AmazonURL As String, ByVal Delay As Integer)
    Dim aHtml As New HtmlWeb
        Dim ChromeAgent As String = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"
    aHtml.UserAgent = ChromeAgent


    Dim proxy As New System.Net.WebProxy
    Dim proxyAddress As New Uri("http://111.111.111/")


    Dim aDoc As HtmlDocument = aHtml.Load("http://www.ipchicken.com", "GET", proxy, System.Net.CredentialCache.DefaultCredentials)

    Dim aNode As HtmlAgilityPack.HtmlNode
    aNode = aDoc.DocumentNode.SelectSingleNode("//div[@id='olpDivId']/span[2]")

    If aNode.InnerText Is Nothing Then

    End If

    Dim UsedPrice1 As String = aNode.InnerText
    Dim i As Integer = UsedPrice1.IndexOf("$")
    Dim UsedPrice As Integer = UsedPrice1.Substring(i + 1)

    System.Threading.Thread.Sleep(Delay)

    Return UsedPrice
End Function

熱門答案

也許嘗試類似以下內容。根據頁面的不同,您可能不需要UTF8轉換。

WebProxy proxy = new WebProxy("proxyname", 8080);
proxy.Credentials = CredentialCache.DefaultCredentials;

WebClient client = new WebClient();
client.Proxy = proxy;

string baseHtml = "";

byte[] pageContent = client.DownloadData("your target url");

UTF8Encoding utf = new UTF8Encoding();
baseHtml = utf.GetString(pageContent);

HtmlDocument pageHtml = new HtmlDocument();
pageHtml.LoadHtml(baseHtml);



許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因