Shrey
Shrey

Reputation: 17

Unable to extract image from website

I am trying to extract an image from the website using python :

relevant command :

import urllib
imagelink =  'http://searchpan.in/hacked_captcha.php?450535633'
urllib.urlretrieve(imagelink, "image.jpg")

using Firefox to view image shows the following.

enter image description here

Upvotes: 1

Views: 209

Answers (4)

Sarath Sadasivan Pillai
Sarath Sadasivan Pillai

Reputation: 7091

The image is png , all you nedd to do is save it as '.png'

Here is the code

import urllib
imagelink =  'http://searchpan.in/hacked_captcha.php?450535633'
urllib.urlretrieve(imagelink, "image.png")

Upvotes: 1

Binay Budhathoki
Binay Budhathoki

Reputation: 65

You could use the following on Python 3. You need to first do a GET request which of-course is abstracted and retrieve the content, writing it to the given filename.

import urllib.request

imagelink =  'https://i.sstatic.net/s2F9o.png'
urllib.request.urlretrieve(imagelink, './sample.png')

Reference https://docs.python.org/3/howto/urllib2.html#fetching-urls

Upvotes: 2

Teshtek
Teshtek

Reputation: 1352

Maybe this on one line?

import urllib.request

urllib.request.urlretrieve("http://searchpan.in/hacked_captcha.php?450535633", "image..jpg")

Upvotes: 1

rofelia09
rofelia09

Reputation: 51

there must be .jpg or whatever extension for img the website is using u have to give the full url with extension

Extract and Download Image

Go to this link It may be helpfull.

Best of luck...

Upvotes: -1

Related Questions