Littellittel
Littellittel

Reputation: 13

c# Html agility pack HtmlDocument does not contain all Elements from the website

I´m making a chatbot. The bot should be able to define a word, so I tried getting the span Element from Google (https://www.google.de/webhp?sourceid=chrome-instant&rlz=1C1CHBD_deDE721DE721&ion=1&espv=2&ie=UTF-8#q=define%20test) where the definition is written in, which didn't work. It turns out that the htmlDocument does not contain the whole website.

    string Url = "https://www.google.de/webhp?sourceid=chrome- instant&rlz=1C1CHBD_deDE721DE721&ion=1&espv=2&ie=UTF-8#q=define%20test";
    HtmlWeb web = new HtmlWeb();
    HtmlDocument doc = web.Load(Url);
    HtmlNode node = doc.DocumentNode.SelectSingleNode("//*[@id='uid_0']/div[1]/div/div[1]/div[2]/div/ol/li[1]/div/div/div[2]/div/div[1]/span");
    if (!String.IsNullOrEmpty(node.InnerText))
        output += node.InnerText;

node is not set to an Instance of an object

I let me give the InnerHtml of the document and put it in a gist: https://gist.github.com/MarcelBulpr/bb44a527d8202eb7fffb4e21fb8b4fed

it seems that the website does not load the result of the search request.

Does anyone know how to work around this?

Thanks in advance

Upvotes: 0

Views: 640

Answers (0)

Related Questions