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

后端 未结 5 1008
走了就别回头了
走了就别回头了 2021-02-09 13:02

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 d

5条回答
  •  耶瑟儿~
    2021-02-09 13:22

    Yes, it is possible.

    What you need to do is the following:

    1. Create a CURL call to that webpage in order to retrieve any parameter used in the Ajax call that loads the content, which you are looking for.
    2. Create another CURL call to the file called by that webpage Javascript using the parameters that you have gotten using step number 1.

    ex. Say you want to get the content of http://www.domain.com/page.html and this page.html retrieves some other data using Ajax, say $("#div").load("http://www.domain.com/ajax/data.php?time=48484&c=487387").

    What you will do is to make a CURL request to page.html first, and get the full URL of the Ajax call using preg_match() PHP function or any equivalent function in any other language. After that, create another CURL request to that URL - http://www.domain.com/ajax/data.php?time=48484&c=487387 - and get its content.

    You're all set!

提交回复
热议问题