What is Javascript Override?

Asked

Viewed 106 times

3

I’m working on a project where I have to do the 'parser' from a remote site to change various contents of it, everything is fine, except the functions that involves javascript/ajax. Functions do not work, website 'parseado' always returns me an error

"sorry we’re in trouble'',

but this error occurs due to javascript. I was wearing a proxy em PHP to make the 'parser', but for being slow, I wanted to make my own, and it’s nothing more than a "link changer":

function parserSite($link){

    $opts = array(
    'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
    )
    );
    $context = stream_context_create($opts);
    $html = file_get_contents($link , false, $context);
    $results = preg_replace('/href="(https:\/\/)?([^"]+)"/', "href=\"https://sitetal.com\\2\"", $html);
    $results = preg_replace('/src="(https:\/\/)?([^"]+)"/', "src=\"https://sitetal.com\\2\"", $results);

reuturn $results
}
$link = $_GET["link"];
$site = parserSite($link);

echo $site;

The site works all right, except the javascript's. In the proxy I used, the same error occurred when I disabled the option "Override Enable Javascript", when this option was enabled, everything worked normally. But what’s this about "Override Enable Javascript"? it is possible for me to do for my script? Posted in PHP e Javascript because I don’t know for sure which of the two languages I’ll have to use for such.

1 answer

3


You are having this difference between the website accessed via browser and the download via PHP because the website in question probably uses javascript to render its parts, what you can do is use a headless browser to simulate a browser accessing the site.

A suggestion is to use the Phantomjs, perhaps with this library to use it through php

  • Thank you so much! I made my browser headless and gave it right ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.