Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2012, 12:46 PM   PM User | #1
osschef
New to the CF scene

 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
osschef is an unknown quantity at this point
Image extraction without reloading from src

Hey there,

There is a foreign site whose content is not under my control.
When I open this site, it contains an image.
Using DOM traversal, I can predictably store the according <img> tag into a variable.

I want that image somehow extracted, without having to intervene manually.

It is intended that other programs, running under my control on localhost, can furtherly manipulate and use the image.
I thought of creating a local web server, and letting the JS send me "some data" via post to that web server.

However, simply reloading from src is NOT possible, since the content changes dynamically (non-idempotent behaviour of the foreign server in response to a get request), and I badly want exactly the same image as displayed in the browser.

According to w3schools, the <img> tag is just a container.
That leaves me with the question: How can I access the image itself (programatically) without reloading it from src?
Google hasn't turned up a result, I'm new to JS, and nobody I know can give me a hint.

Just to make my point clear: I'm only talking about that image-extraction part.
Everything else can be adapted to this (except the foreign server, of course)

(Posted under DOM because I thought the solution might somehow DOM-related. Not sure though.)

osschef
osschef is offline   Reply With Quote
Old 06-21-2012, 12:25 AM   PM User | #2
nibbrwebdevelop
New Coder

 
Join Date: Apr 2012
Location: United Kingdom
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
nibbrwebdevelop is an unknown quantity at this point
Quote:
Originally Posted by osschef View Post
Hey there,

There is a foreign site whose content is not under my control.
When I open this site, it contains an image.
Using DOM traversal, I can predictably store the according <img> tag into a variable.

I want that image somehow extracted, without having to intervene manually.

It is intended that other programs, running under my control on localhost, can furtherly manipulate and use the image.
I thought of creating a local web server, and letting the JS send me "some data" via post to that web server.

However, simply reloading from src is NOT possible, since the content changes dynamically (non-idempotent behaviour of the foreign server in response to a get request), and I badly want exactly the same image as displayed in the browser.

According to w3schools, the <img> tag is just a container.
That leaves me with the question: How can I access the image itself (programatically) without reloading it from src?
Google hasn't turned up a result, I'm new to JS, and nobody I know can give me a hint.

Just to make my point clear: I'm only talking about that image-extraction part.
Everything else can be adapted to this (except the foreign server, of course)

(Posted under DOM because I thought the solution might somehow DOM-related. Not sure though.)

osschef
Could you give more details on how the foreign site is generating the image. Can you show an example of the page in question?

This is probably going to be more complex than just using javascript. You may need to use a server side language such as PHP and manipulate the DOM and use CURL to store cookies, send correct headers etc.
__________________
Providing quality professional Mobile Applications, Web Applications and Website Development Services.
nibbrwebdevelop is offline   Reply With Quote
Old 06-21-2012, 01:47 AM   PM User | #3
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
The reason why the WM have made it this way is because they want to prevent you from using/saving their image.
And they probably also have copyright of the image.

There is no way that you will be able to use/save the image.
And if there was, it would be considered hacking.

These forums rules (1.4: No illegal requests) do not allow you to ask for help with illegal activity.
Lerura is offline   Reply With Quote
Old 06-21-2012, 02:14 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,554
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
you question is unclear.
use html scraping techs to get the img tag attribs, use curl to get the src binary data.

if it's on another server that's not setting access-control headers, use node.js or greasemonkey to run your javascript.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Tags
automation, dom, extraction, image

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:28 AM.


Advertisement
Log in to turn off these ads.