I'm trying to scrape this page http://www.buddytv.com/trivia/game-of-thrones-trivia.aspx and it's not working.
I tried
$html = new simple_html_dom();
$html->load_file($url);
But for the question I'm looking to grab (.trivia-question) can't be found. Can anybody tell me what I'm doing wrong ?
Thanks a lot!
And I tried
<?php
$Page = file_get_contents('http://www.buddytv.com/trivia/game-of-thrones-trivia.aspx');
$dom_document = new DOMDocument();
//errors suppress because it is throwing errors due to mismatched html tags
@$dom_document->loadHTML($Page);
$dom_xpath_admin = new DOMXpath($dom_document_admin);
$elements = $dom_xpath->query('//*[@id="id60questionText"]');
var_dump($elements);
Ok then here is phantomjs example:
You need to download phantomjs from: http://phantomjs.org/, put somewhere where you can easily access by a script.
Test it by running {installationdir}/bin/phantomjs (phantomjs.exe on windows) --version
Then create JS file somewhere in your project, ex browser.js
Then in your PHP script read it like:
Change
$pathToPhatomJs
and$pathToJsScript
according to your configuration.If you are on windows this may not work. You can then change PHP script to: