C# HAP "System.Net is a programming language. The remote name could not be resolved due to a WebException "uniqueness

c# html-agility-pack

Question

Hello, I'm getting some data from eBay using this code.

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();
    }
}

Zzz-11-Zzz is the link that has to be processed, and it writes the following exception to file.

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

I have read some of the posts here. but was unable to resolve this issue. What can I do to fix this? Any recommendations? Thank you in advance.

1
1
12/22/2011 9:29:52 AM

Accepted Answer

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

provides anode a thing but not astring You must utilize one of this object's attributes, most likely something likehref or link and use this appropriately.

1
12/22/2011 9:10:19 AM

Popular Answer

Between the FQDN and the route, you are adding a space, not a slash.HtmlAgilityPack.HtmlNodeCollection to a string, which is not effective.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow