0

I am trying to get the contents of this page with php-phantomjs. After some digging, I noticed that this page first loads this JavaScript code:

function setCookie(c_name, value, expiredays) { // Local function for setting a value of a cookie
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/";
}
function getHostUri() {
    var loc = document.location;
    return loc.toString();
}
setCookie('YPF8827340282Jdskjhfiw_928937459182JAX666', '[request_ip_addr]', 10);
try {  
    location.reload(true);  
} catch (err1) {  
    try {  
        location.reload();  
    } catch (err2) {  
        location.href = getHostUri();  
    }  
}

Which clearly sets a cookie with my IP address, then reloads the page.

I am executing the request from my PHP server this way:

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require 'vendor/autoload.php';

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();
$client->getEngine()
        ->debug(true)
        ->addOption("--cookies-file='/cookies.txt'");

$request = $client->getMessageFactory()->createRequest();
$response = $client->getMessageFactory()->createResponse();

$request->setMethod('GET');
$request->setUrl('https://www.alarabiya.net/.mrss/ar.xml');

$client->send($request, $response);

var_dump($client->getLog());

if ($response->getStatus() === 200) {
    echo $response->getContent();
} else {
    echo 'Error loading data';
}

Which is returning an empty page, a var_dump($response->getContent()) show that it is NULL.

I think that PhantomJS is not executing the location.reload() call, if this is the case can someone tell me how to make follow this reload? Or what might be the problem causing this?

EDIT: The script is working fine when using this link 'http://jonnyw.me' mentioned in the basic usage guide.

hiddeneyes02
  • 2,562
  • 1
  • 31
  • 58

1 Answers1

0

$request->setDelay(3); delay 3s to exe js

V2077
  • 13
  • 5