0

I want to extract all the cells of a specific table on a website. The trouble is that the website has three tables which has no id's but all share the same class names. I can get the three tables and all the cells from each, but i only want the second table. How can i do that with XPath? I have the following code:

$search->domxpathquery = "//table[contains(@class,'price-development-table')]/tbody/tr/td";

$doc = new DOMDocument;
@$doc->loadHTML(file_get_contents($search->url));
$xpath = new DOMXPath($doc);
$needles = $xpath->query("//table[contains(@class,'price-development-table')]/tbody/tr/td");

When instead using only //table[contains(@class,'price-development-table')] i can see that there are three tables.

Can i somehow only select cells from the second of those? I've tried using the below:

//table[contains(@class,'price-development-table') and position()=2]/tbody/tr/td
//table[contains(@class,'price-development-table')][2]/tbody/tr/td

.. but these tries doesnt change anything and still includes all three tables for some reason.

EDIT: Added url I'm trying this on: https://www.q8.dk/priser/prislister/

Daniel Jørgensen
  • 933
  • 1
  • 14
  • 38

0 Answers0