I can get output from a phantom.js request from the command line, and the output is what I expect. I would like to call phantom.js from a php script and then parse the output looking for certain content.
My phantom.js looks like:
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';
page.open('https://www.aa.com/travelInformation/flights/status/detail?search=AA|1698|2019,1,23&ref=search', function(status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function() {
return document.getElementById('aa-content-frame').innerHTML;
});
console.log(ua);
}
phantom.exit();
});
If I run the following from the command line:
phantomjs phantomjstest.js
I get output similar to:
The default user agent is Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1
<app-root-flight-status data="{"queryString":"AA|1698|2019,01,23",
"bffUri":"https://www.aa.com/flightinfo/v1.0/",
"email":"",
"countryCode":"",
"phoneNumber":""}" _nghost-c0="" ng-version="6.1.4"><router-outlet _ngcontent-c0=""></router-outlet><app-flight-details _nghost-c1=""><!----><!----><div _ngcontent-c1=""><!----><h1 _ngcontent-c1=""> Flight status</h1>
... blah blah blah ...
What I would like to do is run phantom.js from within a php script like this:
$response = exec('/usr/bin/phantomjs phantomjstest.js');
and then continue down the php script with the code that parses the output.
When I execute my php script:
<?php
$response = exec('/usr/bin/phantomjs phantomjstest.js');
$query = mysqli_query($link, "INSERT INTO test (t_test) VALUES('11 - " . $response . "')");
echo "Response = <br /><br />".$response;
?>
It appears $response is empty. It is not displayed on the screen and only '11 - ' is added to the database. I assume this is because phantomjstest.js logs 'ua' to the console.
My question is how to get the javascript variable ua to a point where I can parse it in my php script. Any ideas?