Recover Javascript-updated HTML using DOM

Asked

Viewed 209 times

3

Is there any way to recover an updated HTML using DOM? The original HTML page is from a remote site, which I don’t have internal access to, and that’s how it is:

<div class="content" id="content">
        loading
</div>

When we click on a button inside the page, javascript acts, and the div is modifies, getting something like:

<div class="content" id="content">
            <span class="values">text1</span>
            <span class="values">text2</span>
    </div>

I need to retrieve the text tags <span>, which in this case was the javascript who inserted it. I used DOM:

$html = file_get_contents("http://sitetal.com");
$DOM =  new DOMDocument();
$DOM->loadHTML($html);
$xpath = new DomXpath($DOM);
$span = $xpath->query('//*[contains(concat(" ", normalize-space(@class), " "), "values")]');
foreach($span as $spanvalue){
    $sp = floatval($spanvalue[0]->nodeValue);
    $spaValue = $sp;

echo $spaValue;
}

But obviously nothing is returned to me, because the <span> not yet created, it will only be created when it is clicked on the button there of the site, and the javascript insert the information. there is some way to recover the updated HTML, to read the values that was generated in the <span> ? For me to recover text 1 and text 2.?

1 answer

1

The short, thick answer is no, cannot simulate user behavior with PHP requests.

User behaviors can only be done through Javascript and an interpreter is required, in case the browsers have a.

When you submit a request in PHP, you are only ordering dados, cannot emulate behaviors on top of this data.

  • So, what would be the solution for me to rescue these clicked data? Remembering that I am not the programmer of the original site, I can only insert codes into it by a parser I did. Do you know any way to pass such values to me to treat them later on?

Browser other questions tagged

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