0
votes

I am trying to find a tool to capture items from web pages. First i have used xpath finder Firefox addon but sometimes it generated xpath with schemas (xpath 2.0) so it is not suitable

Below is the absolute xpath generated with firepath (firefox) for googles search button

html/body/div[2]/div[1]/div[1]/div[2]/div[2]/div/form/div[1]/button[1]

when i try to

doc.DocumentNode.SelectSingleNode("html/body/div[2]/div[1]/div[1]/div[2]/div[2]/div/form/div[1]/button[1]").InnerText;

it gives null reference exception.

So i cant use firepath too.

I need a tool which works with the HTML Agility Pack. Or need to find out why above does not work.

1
Without seeing the structure of the HTML file, it is difficult to give an answer. Try starting the XPath declaration with a / to root it. Also, does the button element really contain any InnerText??? - Oded

1 Answers

0
votes

While using FirePath, I got good results when I disabled generating absolute XPATH. In your case the xpath generated is

.//*[@id='gbqfb']

But I can write a XPATH query something like below:

//button[@name='btnG']

Not sure why your XPATH query is not working but below seems to work when I removed form tag.

doc.DocumentNode.SelectSingleNode("html/body/div[2]/div[1]/div[1]/div[2]/div[2]/div/div[1]/button[1]").InnerText;