Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

635
Visualizações
PHP / cURL or file_get_contents -- How to get the value of a JS page instead of the JS code

This is hopefully an easy question, but it's giving me an issue. I have a page "sample.html" with a simple script like this in JS:

// sample.html
<script>
    let myNumber = 15;
    document.write(myNumber);
</script>

... and then I want to have a PHP page ("getValue.php") go and get that number (e.g., 15). My problem is: If I do a file_get_contents or even a cURL to that JS page, like so...

// getValue.php
$newVal = file_get_contents('sample.html');

... the $newVal var in PHP is NOT simply the "15" value. Instead, the var is equal to the entire JS script shown. So, how can I use PHP to get that "15" value alone as a variable? In other words, I only want $newVar to be the result of the JS page, not the entire script. What I want to achieve is:

// $newVal == 15

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

TL;DR

With file_get_content you cant do that.

You looking for a php scrapper of JavaScript genertaed content. One tool would be PHP-Webdriver. It base on Selenium.

https://github.com/php-webdriver/php-webdriver

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda