[請益] 請教php爬蟲爬分頁的方式
想擷取圖片的網址為http://www.bsobs.com.tw/photos/index/y/2017/m//page/
目前這支程式可以跑出第一頁的圖片結果
如果要跑出所有分頁的結果我應該怎麼寫呢嗚嗚嗚
跪求高手救援,小弟只是新手阿阿~~~
<?php
//引入套件
require('C:\snoopy\Snoopy.class.php');
require('C:\phpquery\phpQuery\phpQuery.php');
//download url
$url = "http://www.bsobs.com.tw/photos/index/y/2017/m//page/";
//模仿正常人
$snoopy->agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36";
$snoopy->referer = "http://www.bsobs.com.tw/photos/index/y/2017/m//page/";
//擷取HTML
$snoopy = new Snoopy();
$html = $snoopy->fetch($url)->getResults();
//篩選img class
phpQuery::newDocumentHTML($html);
$images = pq('.photos_mobile img');
foreach($images as $image){
preg_match_all("#(http://images/babyphoto/\w+.JPG)#", $html,
$matches);//套用原圖網址
echo $image->getAttribute('src') ."<br>";
}
?>
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.75.138.247
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1491043629.A.2C7.html
→
04/01 19:41, , 1F
04/01 19:41, 1F
→
04/01 19:41, , 2F
04/01 19:41, 2F
→
04/01 19:42, , 3F
04/01 19:42, 3F
→
04/02 01:43, , 4F
04/02 01:43, 4F
推
04/02 07:55, , 5F
04/02 07:55, 5F
→
04/02 07:55, , 6F
04/02 07:55, 6F
→
04/02 07:56, , 7F
04/02 07:56, 7F
→
04/02 07:57, , 8F
04/02 07:57, 8F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章