Simple crawling based on PHPQuery (2) -- crawling content pages

Source: Internet
Author: User
3. next, the second step is to redirect the url in the list page to the corresponding content page to capture the content to generate a document page in the true sense, because there are many pages generated here, it is slow to capture the page content and generate a local page, so the thought of executing and outputting at the same time is: & lt ;? Phpset_time_limit (0); date_default_timezone_s

3. next, the second step is to redirect the url in the list page to the corresponding content page to capture the content to generate a document page in the true sense, because there are many pages generated here, it is slow to capture the page content and generate a local page. Therefore, the thinking of side execution and output is re-integrated:

 Html (); // The Returned string type variable $ arr = preg_split ("/\ n/", $ ); // use a linefeed to split the string into an array unset ($ arr [0]); // print_r ($ arr); ob_end_clean (); // disable the cache area echo date ('Y-m-d H: I: S', time () before loop output ()). "==> start creating PHPQuery user guide... "; flush (); // push directly to browser foreach ($ arr as $ link) {preg_match ("/(. *) <\/a>/", $ link, $ array); // use the regular expression to match the link and text. // print_r ($ array ); $ https = str_replace ("http", "https", $ array [1]); // It is strange that https processed by phpquery is changed to http. change it back here, otherwise, the object cannot be directed to the document. Content page // echo $ https. ""; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ https); curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) chrome/23.0.20.1.1 Safari/537.11 '); $ res = curl_exec ($ ch); $ rescode = curl_g Etinfo ($ ch, CURLINFO_HTTP_CODE); curl_close ($ ch); phpQuery: new1_enthtml ($ res); $ manual = pq ("# wikicontent")-> html (); // obtain the document content. // echo $ manual. ""; $ title = strtolower ($ array [2]); file_put_contents (". /manual /". $ title. ". html ", $ manual); echo $ title. "The page is created successfully! "; Flush (); sleep (1);} echo date ('Y-m-d H: I: S', time ()). "<== the PHPQuery user guide has been created! ";

. In this way, the corresponding document content page is generated under the Directory/manual.

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.