Ways to parse HTML files using the Snoopy class

Source: Internet
Author: User
This article mainly introduces PHP based on Snoopy parsing Web page HTML method, example analysis of the use of Snoopy class parsing HTML files related techniques, with a certain reference value, the need for friends can refer to the following

This article describes the PHP method based on Snoopy parsing Web page HTML, the implementation method is as follows:

Set_time_limit (0); $user = Array (' 20517 ', ' 20518 '); header ("content-type:text/html; Charset=utf-8 "); require_once './snoopy.php '; $snoopy = new Snoopy ();//$uri = ' http://www.juzimi.com/meitumeiju '; $uri = ' http://www.juzimi.com/meitumeiju?page=1 '; $snoopy->fetch ($uri); $con = $snoopy->getresults (); $doc = new DOMDocument (); $doc->loadhtml ($con);/* Make a result array ... */$result = [];/* go through all nodes which has class= " Baby "... * * $i = 0;foreach ((new Domxpath ($doc))->query ('//*[@id =" Bdshare "] ') as $element) {$row = $doc->sa  Vehtml ($element);  $start = Stripos ($row, ' {');  $end = Stripos ($row, '} ');  $len = $end-$start + 1;  $json = substr ($row, $start, $len);  $json = Str_replace ("'", ' "', $json);  $obj = Json_decode ($json);  $pic = $obj->pic;  $desc = $obj->desc; $filename = '/uploads/meiju/card '. Date (' Ymdhis '). $i.  '. png '; $file = '/alidata/www/test '.  $filename;  $image = file_get_contents ($pic); File_put_contents ($file, $image);}

Summary: the above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

Php+mysql+jquery statistics current number of users online

Php+mysql+jquery implementation of Query and list box selection

PHP implementation of digital format, the number of every three comma-plus function function

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.