国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php基于Snoopy解析網(wǎng)頁html的方法

2024-05-04 23:37:37
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php基于Snoopy解析網(wǎng)頁html的方法,實例分析了使用Snoopy類解析html文件的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php基于Snoopy解析網(wǎng)頁html的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

 

 
  1. set_time_limit(0); 
  2. $user = array('20517''20518'); 
  3. header("content-Type: text/html; charset=utf-8"); 
  4. require_once './Snoopy.php'
  5. $snoopy = new Snoopy(); 
  6. //$uri = 'http://www.juzimi.com/meitumeiju'; 
  7. $uri = 'http://www.juzimi.com/meitumeiju?page=1'
  8. $snoopy->fetch($uri); 
  9. $con = $snoopy->getResults(); 
  10. $doc = new DOMDocument(); 
  11. $doc->loadHTML($con); 
  12. /* make a result array ... */ 
  13. $result = []; 
  14. /* go through all nodes which have class="baby" ... */ 
  15. $i = 0; 
  16. foreach( ( new DOMXPath( $doc ) )->query( '//*[@id="bdshare"]' ) as $element ) { 
  17. $row = $doc->saveHTML($element); 
  18. $start = stripos($row, '{'); 
  19. $end = stripos($row, '}'); 
  20. $len = $end - $start + 1; 
  21. $json = substr($row, $start, $len); 
  22. $json = str_replace("'", '"', $json); 
  23. $obj = json_decode($json); 
  24. $pic = $obj->pic; 
  25. $desc = $obj->desc; 
  26. $filename = '/Uploads/meiju/card' . date('ymdhis') . $i . '.png'
  27. $file = '/alidata/www/test' . $filename; 
  28. $image = file_get_contents($pic); 
  29. file_put_contents($file, $image); 

希望本文所述對大家的php程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 赣榆县| 多伦县| 通城县| 屏边| 房产| 沐川县| 安阳县| 淳化县| 东宁县| 临朐县| 湛江市| 兴仁县| 南郑县| 图木舒克市| 仪征市| 安阳县| 辽阳县| 秀山| 潞西市| 濮阳市| 呼玛县| 长寿区| 上饶市| 丰原市| 延津县| 自治县| 文化| 阿克苏市| 利川市| 宝山区| 十堰市| 尉氏县| 灵宝市| 卫辉市| 东城区| 彩票| 孙吴县| 上杭县| 寿阳县| 滨州市| 沙洋县|