Reputation: 3661
What I want to do is following:
Is there any possible way to get image url with Javascript or PHP?
Upvotes: 0
Views: 1623
Reputation: 391
Javascript answer:
Will the output image always have the same class, embeddedObject
?
If so, how about something like:
myVar = document.getElementsByClassName('embeddedObject');
myVar[0].getAttribute("src");
The myVar[0]
reference of course assumes that there is only ever one image on the page with the embeddedObject class, otherwise you'd need to sort, or know which index to reference each time.
Also, this sadly doesn't seem to be supported in IE8 (which browser do you need to support?): http://caniuse.com/getelementsbyclassname
Upvotes: 0
Reputation: 583
you could use Simple PHP DOM Parser to retrieve the image from the url without considering the url for as long as it contains and image inside, like so:
foreach($html->find('div[class=div-that-contain-the image]') as $div) {
foreach($div->find('img') as $img){
echo "<img src='" . $img->src . "'/>";
}
}
That is my solution.
Upvotes: 1
Reputation: 524
Yes. If you right click on the image and go Copy Image Location, you'll see it's http://content.screencast.com/users/TT13/folders/Jing/media/c25ec5c6-bc6a-413c-a50b-ada95fac4ed2/2012-07-25_0221.png
If you were to do it programmatically, you would use cURL and simplehtmldom.sourceforge.net to parse the outputed HTML for the actual link.
Upvotes: 0
Reputation: 29498
You can retrieve the page containing the image using a DOM library like Query Path.
Using that you can extract the URL to the image.
So in your step 3:
file_get_contents
)Upvotes: 0