34

I am trying to grab the score table from a website. The problem is that the site is using javascript that apparently loads on document.ready.

For that reason I don't seem to succeed getting the table and all I get is the buttons at the top of that page.

Any suggestions or ideas on how to solve this?

030
  • 10,842
  • 12
  • 78
  • 123
m33ts4k0z
  • 391
  • 1
  • 6
  • 10

2 Answers2

29

cURL will only get you the markup of the page. It won't load any additional resources or process the page. You probably want to look at something like PhantomJS for this. PhantomJS is a headless WebKit browser. It has its own API that lets you "script" behavior. So you can tell PhantomJS to load the page and dump out the data you need.

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
  • Thanks for your answer. I will need to run this as JavaScript and then save the dump to a PHP variable using the exec command. Is that correct? – m33ts4k0z Dec 12 '13 at 21:17
  • You don't have to, actually. You can run it directly from the command line. But if you are using this to display it on a website, then yes you can use `exec` from PHP. – Vivin Paliath Dec 12 '13 at 21:54
6

Depending on what exactly you're trying to do, you could just fetch the JSON data that makes the table:

http://www.opap.gr/web/services/rs/betting/availableBetGames/sport/program/4100/0/sport-1.json?localeId=el_GR

Lasse
  • 1,414
  • 11
  • 19
  • Thanks for your answer. I will mark Vivins answer as the answer to my question but yours was also really good. I wonder how did you find the json call? – m33ts4k0z Dec 12 '13 at 21:18
  • 1
    @m33ts4k0z: No problem. I found it by using the "Network" tab of Chrome's Developer Tools (The same is possible in other browsers as well). Since `document.ready` was involved I guessed that the page probably loaded the information externally. – Lasse Dec 12 '13 at 21:22
  • @PradeepKumarPrabaharan 3 years later LOL – niCk cAMel Sep 25 '18 at 20:51