【发布时间】:2014-06-06 18:52:15
【问题描述】:
我正在构建一个爬虫,它从网站的网页开始,例如 example.com,并找到该页面上位于同一域中的所有链接。
假设我们在这个页面上有example.com/hello.php、facebook.com/hello.php。所以我只想列出 www.example.com/hello.php。
我正在使用 PHP Simple HTML DOM Parser(simplehtmldom.sourceforge.net/)。
$html = file_get_html('http://www.example.com/');
// Find all links
foreach($html->find('a') as $element) {
$uri = $element->href;
//Now how to check if $uri belongs to same domain?
}
【问题讨论】:
标签: php web-crawler