I would like to know and understand how I can add javascript code to my current code in order to perform actions such as a click on a page that I loaded using phantomjscloud using their api.
Here is my current code, it works and returns the HTML code of the page correctly but not the one after the click:
PHP :
<?php
$apikey = "";
$url = 'http://PhantomJScloud.com/api/browser/v2/'.$apikey.'/';
$payload = file_get_contents ( 'request.json' );
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $payload
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
?>
Json :
{
"pages":[
{
"url": "http://myurl.com",
"content": null,
"urlSettings": {
"operation": "GET",
"encoding": "utf8",
"headers": {},
"data": null
},
"renderType": "HTML",
"outputAsJson": false,
"requestSettings": {
"ignoreImages": false,
"disableJavascript": false,
"userAgent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) Safari/534.34 PhantomJS/2.0.0 (PhantomJsCloud.com/2.0.1)",
"xssAuditingEnabled": false,
"webSecurityEnabled": false,
"resourceWait": 15000,
"resourceTimeout": 35000,
"maxWait": 35000,
"waitInterval": 1000,
"stopOnError": false,
"resourceModifier": [],
"customHeaders": {},
"clearCache": false,
"clearCookies": false,
"cookies": [{
"domain": "",
"httponly": true,
"name": ".AspNetCore.Cookies",
"path": "/",
"secure": false,
"value": ""
}],
"deleteCookies": []
},
"suppressJson": [
"events.value.resourceRequest.headers",
"events.value.resourceResponse.headers",
"frameData.content",
"frameData.childFrames"
],
"renderSettings": {
"quality": 70,
"pdfOptions": {
"border": null,
"footer": {
"firstPage": null,
"height": "1cm",
"lastPage": null,
"onePage": null,
"repeating": "%pageNum%/%numPages%"
},
"format": "letter",
"header": null,
"height": null,
"orientation": "portrait",
"width": null
},
"clipRectangle": null,
"renderIFrame": null,
"viewport": {
"height": 1280,
"width": 1280
},
"zoomFactor": 1,
"passThroughHeaders": false
},
"scripts": {
"domReady": [],
"loadFinished": []
}
}
],
"proxy":false
}
I think I need to add javascript code in the JSON in "scripts" but I don't know how to go about it, thank you