国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 府谷县| 涡阳县| 祁门县| 平江县| 泸西县| 宁远县| 衡东县| 霍林郭勒市| 承德县| 民县| 铅山县| 麻江县| 红河县| 南漳县| 永济市| 新绛县| 德格县| 万载县| 岳西县| 子洲县| 博乐市| 通许县| 岑巩县| 崇文区| 潜山县| 江西省| 颍上县| 正宁县| 高平市| 宝坻区| 滨海县| 武宣县| 获嘉县| 华容县| 大田县| 克拉玛依市| 平度市| 湖口县| 罗甸县| 右玉县| 三都|