Using PHP Method Curl Grab Ajax asynchronous content thinking analysis and code sharing _php example

Source: Internet
Author: User
In fact, grab Ajax asynchronous content of the page and catch the ordinary page is not very different. Ajax simply makes an asynchronous HTTP request, as long as it uses firebug-like tools to find the requested backend service URL and value-passing parameters, and then fetches the URL parameters.

Using Firebug's Network Tools

If you are grabbing a page, the data that is not displayed in the content is a bunch of JS code.

Code

$cookie _file=tempnam ('./temp ', ' Cookie '); $ch = Curl_init (); $url 1 = "http://www.cdut.edu.cn/default.html"; curl_ Setopt ($ch, Curlopt_url, $url 1); curl_setopt ($ch, curlopt_http_version,curl_http_version_1_1); curl_setopt ($ch, curlopt_header,0); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, curlopt_followlocation,1); curl_ Setopt ($ch, curlopt_encoding, ' gzip '); Add gzip parse//Set file curl_setopt ($ch, Curlopt_cookiejar, $cookie _file) to save cookie information after connection ends; $content =curl_exec ($ch); curl_ Close ($ch); $ch 3 = Curl_init (); $url 3 = "Http://www.cdut.edu.cn/xww/dwr/call/plaincall/portalAjax.getNewsXml.dwr"; $ Curlpost = "callcount=1&page=/xww/type/1000020118.html&httpsessionid=12a9b726e6a2d4d3b09de7952b2f282c &scriptsessionid=295315b4b4141b09da888d3a3adb8faa658&c0-scriptname=portalajax&c0-methodname= Getnewsxml&c0-id=0&c0-param0=string:10000201&c0-param1=string:1000020118&c0-param2=string:news _&c0-param3=number:5969&c0-param4=number:1&c0-param5=null:null&c0-param6=null:Null&batchid=0 "; curl_setopt ($ch 3,curlopt_url, $url 3); curl_setopt ($ch 3,curlopt_post,1); curl_setopt ($ch 3, Curlopt_postfields, $curlPost);//Set the file curl_setopt ($ch 3,curlopt_cookiefile, $cookie _file) that holds cookie information after the connection is completed; $content 1=curl_exec ($ch 3); Curl_close ($ch 3);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.