views:

124

answers:

2

I need some help with screen scraping a site (http://website.com).

Lets say I'm trying to get an image inside 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 ?

Any help at all would be so wonderful.

A: 

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.

Sabeen Malik
Well, this is what I'm attempting to do:// find all div tags with id=product_designforeach($html->find('div#product_design') as $e) $e = str_replace('product_large_images', 'http://www.website.com/product_large_images/', $e); echo $e->innertext;Nothing shows up. Do I have the code wrong?
TJ
you are printing out $e->innertext where as u are replacing the $e object with a string , so thats something to look at.
Sabeen Malik
I don't get it, I'm sorry. I'm totally a noob. Could you please explain? That code was true code I'm using. THANKS SO MUCH
TJ
first try print_r($html->find('div#product_design')); ... see what that outputs .... for instance the link is contained in innertext .. then use something like this ........ $e->innertext = str_replace('product_large_images','website.com/product_large_images', $e->innertext);
Sabeen Malik
A: 
$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.

cballou