Home > Backend Development > PHP Tutorial > php抓取这个页面的内容,该如何解决

php抓取这个页面的内容,该如何解决

WBOY
Release: 2016-06-13 12:04:46
Original
852 people have browsed it

php抓取这个页面的内容

需要抓取的部分已经用红线标出来,
只需要抓取第一页的就可以,
抓取页面:http://www.mafengwo.cn/yj/10206/2-0-1.html
一以前都是用这个类simple_html_dom.php,但是这个我用这个类抓取不出来了
------解决方案--------------------
可以用正則提取。
------解决方案--------------------
不至于吧?

include 'simple_html_dom.php';<br />$opts = array( <br />  'http'=>array( <br />    'user_agent' => $_SERVER['HTTP_USER_AGENT']<br />  ) <br />); <br />$context = stream_context_create($opts); <br />$url = 'http://www.mafengwo.cn/yj/10206/2-0-1.html';<br /> <br />$html = file_get_html($url, false, $context);<br />$div = $html->find('div.post-list ul');<br />foreach($div[0]->find('li') as $i=>$item) {<br />  echo $item->find('img')[0]->src, PHP_EOL;<br />  echo trim($item->find('h2')[0]->text()), PHP_EOL;<br />  echo trim($item->find('div')[3]->text()), PHP_EOL;<br />  //echo '**', $item->innertext(), PHP_EOL;<br />}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template