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
var page = require('webpage').create();
page.open('http://www.buddytv.com/trivia/game-of-thrones-trivia.aspx', function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
search = page.evaluate(function() {
return $('#id60questionText').text();
});
console.log(search);
phantom.exit()
});
})
Then in your PHP script read it like:
$pathToPhatomJs = '/home/aurimas/Downloads/phantomjs/phantomjs-1.9.1-linux-x86_64/bin/phantomjs';
$pathToJsScript = '/home/aurimas/Downloads/phantomjs/phantomjs-1.9.1-linux-x86_64/browser.js';
$stdOut = exec(sprintf('%s %s', $pathToPhatomJs, $pathToJsScript), $out);
echo $stdOut;
Change $pathToPhatomJs
and $pathToJsScript
according to your configuration.
If you are on windows this may not work. You can then change PHP script to:
$pathToPhatomJs = '/home/aurimas/Downloads/phantomjs/phantomjs-1.9.1-linux-x86_64/bin/phantomjs';
$pathToJsScript = '/home/aurimas/Downloads/phantomjs/phantomjs-1.9.1-linux-x86_64/browser.js';
exec(sprintf('%s %s > phatom.txt', $pathToPhatomJs, $pathToJsScript), $out);
$fileContents = file_get_contents('phatom.txt');
echo $fileContents;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…