PHP中图像链接的屏幕抓取 [英] Screen Scraping of Image Links in PHP

查看:78
本文介绍了PHP中图像链接的屏幕抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,其中包含许多不同的产品页面,并且每个页面在所有页面上都有一定数量的相同格式的图像.我希望能够在屏幕上抓取每个页面的网址,以便可以从每个页面检索每个图像的网址.想法是为由热链接图像组成的每个页面创建一个画廊.

I have a website that contains many different pages of products and each page has a certain amount of images in the same format across all pages. I want to be able to screen scrap each page's url so I can retrieve the url of each image from each page. The idea is to make a gallery for each page made up of hotlinked images.

我知道这可以在php中完成,但是我不确定如何为多个链接抓取页面.有什么想法吗?

I know this can be done in php, but I am not sure how to scrap the page for multiple links. Any ideas?

推荐答案

我建议使用DOM解析器,例如PHP自己的

I would recommend using a DOM parser, such as PHP's very own DOMDocument. Example:

$page = file_get_contents('http://example.com/images.php');
$doc = new DOMDocument(); 
$doc->loadHTML($page);
$images = $doc->getElementsByTagName('img'); 
foreach($images as $image) {
    echo $image->getAttribute('src') . '<br />';
}

这篇关于PHP中图像链接的屏幕抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆