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 />';
}