php – Retrieve javascript-updated HTML using DOM


Is there any way to retrieve an updated HTML using DOM? The original HTML Page is from a remote site, which I don't have internal access to, and it looks like this:

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

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

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

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

$html = file_get_contents("");
$DOM =  new DOMDocument();
$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, as the <span> has not yet been created, it will only be created when the button on the site is clicked, and the javascript inserts the information. is there any way to retrieve the updated HTML, to read the values ​​that was generated in the <span> ? For me to retrieve text 1 and text 2.?


The short blunt answer is no, it is not possible to simulate user behavior with PHP requests .

User behavior can only be done through Javascript and an interpreter is required, in case browsers have one.

When you send a request in PHP, you are only requesting dados , it is not possible to emulate behavior on top of that data.

Scroll to Top