【发布时间】:2016-12-20 04:44:00
【问题描述】:
实际上,我正在为我的迷你项目编写一个网络爬虫。 我只想抓取那些只属于输入网站的网页。我希望我的网络爬虫不会爬到除了现在给出的输入之外的其他网站。
这就是我正在做的事情:
$url = $_POST["url"];
$web = @file_get_contents($url);
preg_match_all("/<a\s.*href=\"(.*)\"/U", $web, $matches);
我想做的是:
$url = $_POST["url"];
$web = @file_get_contents($url);
preg_match_all("/<a\s.*href=\"(.*$url.*)\"/U", $web, $matches);
例如:
输入:https://www.google.com/
那么正则表达式应该是:
preg_match("/.*google.com.*/U", xyz, xyz);
任何其他建议都会有所帮助,在此先感谢。
【问题讨论】:
-
欢迎来到stackoverflow 火影忍者君。提出一个明确的问题会更容易帮助你。请阅读这篇文章以确保您得到一个好的答案stackoverflow.com/help/how-to-ask
标签: php regex web-crawler preg-match preg-match-all