Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

633
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda