1
libxml_use_internal_errors(true);
$url = 'http://thepiratebay.is/browse/200/0/7';
$html = file_get_contents($url);
$dom = new \DOMDocument();
$dom->loadHTML($html);
$x = new \DOMXPath($dom);
$nodeList = $x->query('/html/body/div[2]/div[2]/table/tbody/tr');
foreach ($nodeList as $node) {
    die(var_dump($node));
}

Gives me the error:

"Invalid argument supplied for foreach()"

Not sure why xpath doesn't work on that domain?

Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131
  • 1
    Have you `var_dump`ed the contents of `$html` just to make sure your XPath query corresponds to the structure of what you're fetching? – Havelock Apr 29 '13 at 14:01
  • 1
    I couldn't find `tbody` anywhere in the source of the page either... – Havelock Apr 29 '13 at 14:04
  • 1
    @Havelock +1. In cases where the error is because a parsed content is not being seen, it is very helpful to have the content in question also to be pasted as part of the question (at least the relevant part, in case it is a huge data - or maybe in some online HTML pastebin) – raidenace Apr 29 '13 at 14:05
  • @Raidenace the OP has provided the URL... Right mouse click -> show page source (in FF) – Havelock Apr 29 '13 at 14:08
  • 1
    @Havelock - many systems do not give access to torrent sites.. – raidenace Apr 29 '13 at 14:13

1 Answers1

1

If I'm right you'd like to get all the titles in that table. I'd suggest an easier, yet more specific XPath query, i.e.

$nodeList = $x->query('//div[@class="detName"]');

See it in action

Havelock
  • 6,913
  • 4
  • 34
  • 42
  • I used firebug's 'copy xpath' to get the xpath. Do you by any chance know why that doesn't work? I'll go study the xpath now to write it manually :p – Tjorriemorrie Apr 30 '13 at 07:13
  • @Tjorriemorrie, to be honest, I can't tell you why Firebug didn't get it right. But in my opinion nothing beats knowing the background of things when using tools to help you. – Havelock May 01 '13 at 07:46