How to use php to parse Web html based on Snoopy
This article is about how to use php to parse the html of a web page based on Snoopy. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The specific implementation methods are 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 have class= "baby"... * / $I = 0 as foreach ((new DOMXPath ($doc))-> query ('/ * [@ id= "bdshare"]') as $element) {$row = $doc- > saveHTML ($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);} Thank you for reading! This is the end of this article on "how to use php to parse web html based on Snoopy". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!