Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用php编写这个爬虫程序?_Php_Curl_Html Parsing_Web Crawler - Fatal编程技术网

如何用php编写这个爬虫程序?

如何用php编写这个爬虫程序?,php,curl,html-parsing,web-crawler,Php,Curl,Html Parsing,Web Crawler,我需要创建一个php脚本 想法很简单: 当我向这个php脚本发送一个blogpost链接时,就会对网页进行爬网,第一个带有标题页的图像就会保存在我的服务器上 什么PHP函数我必须用于此爬虫程序?使用 现在,$images数组具有给定网页的图像链接。现在,您可以在数据库中存储所需的图像。好吧,您必须使用很多函数:) 但是我假设您特别询问如何查找图像,并说您应该使用DOM解析器,比如,然后使用curl来获取第一个img元素的src。我将使用用户和正则表达式来提取第一个图像标记src属性 或者,在这种

我需要创建一个php脚本

想法很简单:

当我向这个php脚本发送一个blogpost链接时,就会对网页进行爬网,第一个带有标题页的图像就会保存在我的服务器上

什么PHP函数我必须用于此爬虫程序?

使用


现在,
$images
数组具有给定网页的图像链接。现在,您可以在数据库中存储所需的图像。

好吧,您必须使用很多函数:)

但是我假设您特别询问如何查找图像,并说您应该使用DOM解析器,比如,然后使用curl来获取第一个img元素的src。

我将使用用户和正则表达式来提取第一个图像标记
src
属性

或者,在这种情况下,HTML解析器似乎有些过分,但欢迎您查看。

HTML解析器:


功能:您可以获取外部html文件、http或ftp链接并解析内容。

CURL
file\u get\u contents()更快。
// Create DOM from URL
$html = file_get_html('http://www.example.com/');

// Find all images
$images = array(); 
foreach($html->find('img') as $element) {
       $images[] = $element->src;
}