I have this link where i need to do some scraping using xPath and domDocument on that table. I need to to get the name of chemmical, link and part. I've tried using xPath helper in chrome but with no luck, it doesn't make the right query. Any ideas what i'm doing wrong? I'm using this query: //table/tbody/tr/td/a
Asked
Active
Viewed 205 times
1 Answers
1
I am able to get the data you are looking for by using the xPath helper in Chrome in the following manner (these lines are typed into the Chrome console):
All chemicals / first chemical:
> allChemicals = $x("descendant::tr/td[(position() =1)]")
> firstChemical = allChemicals[0].innerText
All links / first link:
> allLinks = $x("descendant::tr/td[(position() =1)]/a")
> firstLink = allLinks[0].href
All parts / first part:
> allParts = $x("descendant::tr/td[(position() =2)]")
> firstPart = allParts[0].innerText
Hope that helps.

David Tansey
- 5,813
- 4
- 35
- 51
-
yes your xPath works great found out there is a console for xPath where you can build queries.. interesting :-d yet even if they work seems that when i use the same thing in php doesn't select the same way strange. – Bogdan May 06 '13 at 10:39