2009-11-06 130 views
0

我需要一些帮助与屏幕刮一个网站(http://website.com)。刮相对路径图像

比方说,我想进去<div id="imageHolder"> 图像但是,当我把它拉下来,它的路径是相对的,即“image_large/imageName.jpg”(我要每天拉下这个形象,它改变每天,它总是以“images_large /。

我怎么能去和预先设置网址website.com里面<div id="imageHolder">

回答

0

该图像再杀数据后,u可以使用str_replace函数来代替” image_large/“与”http://website.com/image_large/“...这就是最简单的我认为

这将取代HTML中的所有相似的图像路径,或者如果你只是想要一个图像,我认为另一个用户已经给你一个解决方案。没有得到任何简单的,我认为。

+0

好了,这就是我试图做的: //找到所有div标签使用id = product_design 的foreach($ HTML的“发现( 'DIV#product_design')为$ E) \t $Ë = str_replace('product_large_images','http://www.website.com/product_large_images/',$ e); echo $ e-> innertext; 什么也没有显示。我的代码有错吗? – 2009-11-06 18:46:11

+0

您正在打印出$ e-> innertext,其中您正在用字符串替换$ e对象,因此需要查看一些内容。 – 2009-11-06 19:27:15

+0

我不明白,对不起。我完全是一个小菜鸟。你能解释一下吗?该代码是我正在使用的真实代码。非常感谢 – 2009-11-06 20:53:20

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的连接运算符,将相对图像路径附加到您的抓取的URL上。