PHP基于Web的scraper

时间:2012-11-24 06:24:42

标签: php html scrape

我想要做的是使用PHP来抓取我输入参数的网址。

我想要整个原始源代码..但那不是全部..

我希望它保存到一个html页面,然后保存到php脚本的本地服务器上。

这是否有简易代码段?或者有人可以轻易地给我写一个代码吗?

例如

我想要抓http://google.com

例如,mysite.com/scrape.php?url = http://google.com

我希望它将google的首页保存到http://mysite.com/scraped/google.com.html

1 个答案:

答案 0 :(得分:2)

这是一个脚本,它将指定网址的内容保存到名为scraped.html的文件中:

if (isset($_GET['url'])):
   $contents = file_get_contents($_GET['url']);
   file_put_contents('scraped.html', $contents);
endif;

要在file_get_contents()来电中使用网址,您必须在php.ini文件中启用allow_url_fopen

当然,这只会保存所请求网址的实际来源,而不会保存任何其他资源,例如图片,脚本和样式表。

相关问题