1
Vote

Exception when connecting to a url

description

Hi,

I do get the following exception when i try to connect to a url via "NSoup.NSoupClient.Connect(url).Timeout(10000000).Get(); using NSoup 0.7.1 "

Error: "FirstElementSibling = '(((NSoup.Nodes.Element)(doc))).FirstElementSibling' threw an exception of type 'System.NullReferenceException'"

Mycode
private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            string url = "http://www.colombopage.com/";
            Document doc = NSoup.NSoupClient.Connect(url).Timeout(10000000).Get();
            Elements links = doc.Select("a[href]");

            foreach (Element it in links)
            {
                Elements src = it.GetAllElements();
                String href = src.Attr("abs:href");

                if (href.Contains(url))
                {
                    textBox1.AppendText(href + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \r\n");
                    textBox1.AppendText(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> \r\n");
                }
            }
        }
        catch (Exception ex)
        {
            textBox1.AppendText(ex.ToString() + " \r\n");
        }
              }
Please let me know how can i solve this issue.

Din

comments