Scraping relative path image
I need some help with screen scraping a site (http://website.com).
Lets say I'开发者_JAVA百科m trying to get an image inside <div id="imageHolder">
But when I pull it down, it's path is relative ie "image_large/imageName.jpg" (I'm going to pull down this image daily as it changes daily. It always begins with "images_large/.
How can I go in and prepend the url website.com to that image inside <div id="imageHolder">
?
$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;
This is just making basic usage of PHP's concatenation operator, ., to append the relative image path onto your scraped URL.
after scrapping the data , u can use str_replace to replace "image_large/" with "http://website.com/image_large/" ... thats the simplest i think
this will replace all similar image paths in the html.. or if u just want one image out of it , i think another user has given u a solution for that. doesnt get any simpler that that i think.
精彩评论