刮擦相对路径图像

时间:2009-11-06 18:14:16

标签: php screen-scraping

我需要一些屏幕抓取网站的帮助(http://website.com)。

让我说我正试图在<div id="imageHolder">内找到一张图片 但是当我把它拉下来时,它的路径是相对的,即“image_large / imageName.jpg”(我每天都会在每天更换时将这张图片拉下来。它始终以“images_large /.

开头

如何在<div id="imageHolder">内进入并将url website.com添加到该图片中?

2 个答案:

答案 0 :(得分:0)

在删除数据之后,你可以使用str_replace将“image_large /”替换为“http://website.com/image_large/”......这是我认为最简单的

这将替换html中的所有类似图像路径..或者如果你只想要一个图像,我认为另一个用户给了你一个解决方案。并没有让我觉得更简单。

答案 1 :(得分:0)

$url = 'http://www.website.com/';

// screen scraping here

// say you have your image you scraped stored in the variable below
$img = 'images_large/imageName.jpg';

// your new full path to the image
$fullpath = $url . $img;

// test it (just to see for yourself)
echo $fullpath;

这只是基本使用PHP的连接运算符,将相对图像路径附加到您的已删除网址上。