php抓取这个页面的内容
需要抓取的部分已经用红线标出来,
只需要抓取第一页的就可以,
抓取页面:http://www.mafengwo.cn/yj/10206/2-0-1.html
一以前都是用这个类simple_html_dom.php,但是这个我用这个类抓取不出来了
------解决方案--------------------
可以用正則提取。
------解决方案--------------------
不至于吧?include 'simple_html_dom.php';
$opts = array(
'http'=>array(
'user_agent' => $_server['http_user_agent']
)
);
$context = stream_context_create($opts);
$url = 'http://www.mafengwo.cn/yj/10206/2-0-1.html';
$html = file_get_html($url, false, $context);
$div = $html->find('div.post-list ul');
foreach($div[0]->find('li') as $i=>$item) {
echo $item->find('img')[0]->src, php_eol;
echo trim($item->find('h2')[0]->text()), php_eol;
echo trim($item->find('div')[3]->text()), php_eol;
//echo '**', $item->innertext(), php_eol;
}