PHP page Crawler

Source: Internet
Author: User

Reptiles must be well understood by the script to crawl the target file.

I'd like to get a daily vegetable price.

To view the console, if there is information about the interface naturally convenient, but directly request the interface to obtain data.

Filtering filtering is required for page information.

The information in the graph is very regular and easy to filter.

First get the entire page, you can use Curl to request the page address, curl is also easy to need to verify the information of the page pass parameters.

Filter page data can be replaced with regular expression matching.

<?PHPHeader("content-type:text/html; Charset=utf-8 " ); $ch=Curl_init (); $url= "Http://www.xinfadi.com.cn/marketanalysis/0/list/1.shtml"; curl_setopt ($ch, Curlopt_useragent, "mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/68.0.3440.75 safari/537.36 " ); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_returntransfer, 1); $content=curl_exec ($ch); Preg_match_all("/<td style=\" text-align:left;padding-left:5px;\ "> (. *?) <\/td><td> (. *?) <\/td><td> (. *?) <\/td><td> (. *?) <\/td><td> (. *?) <\/td><td> (. *?) <\/td><td> (. *?) <\/td>/",$content,$matchs,Preg_set_order); Print_r($matchs);

This is done, the main is to use regular expressions to filter the page, crawling image is the same.

PHP page Crawler

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.