Home > Backend Development > PHP Tutorial > 求助,关于php采集url地址

求助,关于php采集url地址

WBOY
Release: 2016-06-23 14:11:56
Original
997 people have browsed it

我想在如下网页采集所有的帖子url地址

http://www.discuz.net/forum-10-1.html
Copy after login


帖子格式为
http://www.discuz.net/thread-3265731-1-1.html
Copy after login


只要url链接,得出的结果一行一个


回复讨论(解决方案)

$url = 'http://www.discuz.net/forum-10-1.html';$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)');$htmls = curl_exec($ch);curl_close($ch);$doc = new DOMDocument();libxml_use_internal_errors(true);$doc->loadHTML($htmls);$xpath = new DOMXPath($doc);$nodeList = $xpath->query('//a/@href');for ($i = 0; $i < $nodeList->length; $i++) {	if(preg_match('@\/thread\-@',$nodeList->item($i)->value,$match)){		echo $nodeList->item($i)->value. "<br/>";	}}
Copy after login

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