FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

access to a javascript variable in DOM #398

Open behnamshateri opened 4 years ago

behnamshateri commented 4 years ago

I use guotte for scrapping a web page in laravel. I need to get part of data that is in a variable in the script tag in DOM on loaing page:

<script type="text/javascript">
  var matchData = {
            sportId: 0,
            id: 81020
       }
</script>

i need all data that is in matchData parameter that load in the DOM when page is loaded.

Nemesis19 commented 4 years ago

you can use some regex like this:

$node = $crawler->filterXPath('//script[contains(.,"matchData")]')->text();

you should be able then with a regex to get that content