The example in this article describes PHP's approach to parsing Web page HTML based on Snoopy. Share to everyone for your reference. 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 have class= "Baby" ... * * $i = 0;
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);
}
I hope this article will help you with your PHP programming.