php基于Snoopy解析网页html的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了php基于Snoopy解析网页html的方法。分享给大家供大家参考。具体实现方法如下:

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);
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

Admin generator, filters and I18n

Three easy steps 1) configure function Add an input for each field you want to include in you...

PHP翻页跳转功能实现方法

我们都知道用php+mysql在web 页实现数据库资料全部显示是非常简单而有趣的,数据库资料很少的情况下页面显示还是让人满意的,但是当数据库资料非常多的情况下,页面的显示情况将会变的非...

PHP页面跳转操作实例分析(header方法)

本文实例分析了PHP页面跳转操作。分享给大家供大家参考,具体如下: 跳转 header()为php函数,向浏览器发送指定命令 html: <meta http-equiv="...

php绘图之生成饼状图的方法

本文实例讲述了php绘图之生成饼状图的方法。分享给大家供大家参考。具体如下: 这里要实现的功能是人口分布比例图,由扇形组成一个圆,每个扇形颜色不一样。 复制代码 代码如下:<...

NOD32 v2.70.32 简体中文封装版 提供下载了

软件大小  11.8 MB   软件类别  汉化软件/病毒防治 运行环境 Win2003, WinXp, Win2000, Nt, WinMe,...