C#HAP“System.Net.WebException:無法解析遠程名稱”異常

c# html-agility-pack

嗨,我正在使用此代碼從ebay獲取一些數據。

string url = textBox1.Text;
get_all_link(url);
private void get_all_link(string url)
{
    var webGet = new HtmlWeb();

    try
    {
        var document = webGet.Load(url);

        MessageBox.Show(url);
        var metaTags = document.DocumentNode.SelectNodes("//div[@class='ttl']/a");
        if (metaTags != null)
        {
            foreach (var tag in metaTags)
            {
                string link = tag.Attributes["href"].Value;
                links.Add(link);
            }
        }

        var next = document.DocumentNode.SelectNodes("//td[@class='botpg-next']/a");
        if (next != null)
        {
            string link = "http://www.ebay.com" + next;
            get_all_link(link);
        }
        else return;
    }
    catch (Exception f)
    {
        MessageBox.Show(f.ToString());

        TextWriter tw = new StreamWriter("data.txt");
        tw.WriteLine(f.ToString());
        tw.Close();
    }
}

這是要解析的鏈接: http ://www.ebay.com/sch/i.html?_nkw = gruen + -sara + -quartz + -embassy + -bob + -robert + -elephants + -adidas&__sacat = 0& LL_Auction = 1& _dmpt = Watswatches&_odkw = gruen-- sara + -quartz + -embassy + -bob + -robert + -elephants + -adidas&_osacat = 1&_trksid = p3286.c0.m270.l1313並且它在文件中寫入以下異常

System.Net.WebException: The remote name could not be resolved: 'www.ebay.comhtmlagilitypack.htmlnodecollection'
at System.Net.HttpWebRequest.GetResponse()
at HtmlAgilityPack.HtmlWeb.Get(Uri uri, String method, String path, HtmlDocument doc, IWebProxy proxy, ICredentials creds) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1446
at HtmlAgilityPack.HtmlWeb.LoadUrl(Uri uri, String method, WebProxy proxy, NetworkCredential creds) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1563
at HtmlAgilityPack.HtmlWeb.Load(String url, String method) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1152
at HtmlAgilityPack.HtmlWeb.Load(String url) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1107
at BackgroundWorker.Form1.get_all_link(String url) in C:\Documents and Settings\maruf\My Documents\Visual Studio 2008\Projects\BackgroundWorker\BackgroundWorker\Form1.cs:line 86

我在這裡查了一些帖子。但無法解決這個問題。我怎麼解決這個?有什麼建議??提前致謝 :)

一般承認的答案

var next = document.DocumentNode.SelectNodes("//td[@class='botpg-next']/a");

返回node對象而不是string 。你需要使用這個對象的一個屬性,可能是像hreflink這樣的東西,並相應地使用它。


熱門答案

您沒有在FQDN和路徑之間添加斜杠,而是在字符串中添加HtmlAgilityPack.HtmlNodeCollection ,這將無效。



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