我需要创建一个 php 脚本。
思路很简单:
当我将博客文章的链接发送到此 php 脚本时,网页就会被抓取,并且带有标题页的第一张图片会保存在我的服务器上。
我必须为这个爬虫使用什么 PHP 函数?
最佳答案
// 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;
}
现在 $images
数组包含给定网页的图像链接。现在您可以将所需的图像存储在数据库中。
关于php - 如何用php写这个爬虫?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3815712/