Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get content of a javascript/ajax -loaded div on a site?

I have a PHP-script that loads page-content from another website by using CURL and simple_html_dom PHP library. This works great. If I echo out the HTML returned I can see the div-content there.

However, if I try to select only that div with the simple_html_dom, the div always returned empty. At first I didn't know why. Now I know that it's because its content apparently is populated with javascript/ajax.

How would I get the content of the site and then be able to select the div-content AFTER the javascript has populated it with the correct content?

Is it even possible? Thanks!

like image 922
Tanax Avatar asked Sep 02 '11 17:09

Tanax


People also ask

How can I see the content of a div?

To check if a div element contains specific text: Use the textContent property on the element to get the text content of the element and its descendants. Use the includes() method to check if the specific text is contained in the div . If it is, the includes() method returns true , otherwise false is returned.


2 Answers

Yes its piece of cake if you are interested only in that particular html which is returned by ajax.

  1. Gather information like url, parameters and request type (post/get) from that ajax request.
  2. Generate the same request from your php/curl code and you got it.
  3. And hope that server logic will not check who sent the request.
like image 157
Imran Naqvi Avatar answered Sep 28 '22 18:09

Imran Naqvi


For this kind of screen scraping you could try phpQuery or Snoopy.

phpQuery has a web browser plugin and scoopy claims to simulate one

like image 32
Felipe Sabino Avatar answered Sep 28 '22 17:09

Felipe Sabino