Page 1 of 1

Retrieve JPG from url [solved]

Posted: Thu Mar 31, 2016 10:46 am
by dverleysen
Hey,

On my foscam I can retrieve an image by the url, but I what to save that image to my raspberry with a python script.
url = http://192.168.0.184:88/cgi-bin/CGIProx ... R&pwd=PASS

I've tried already this script, but i've got always a black JPG file. (74K)
When I save the image manually it's about 144KB

Code: Select all

import urllib
resource = urllib.urlopen("http://192.168.0.184:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=USER&pwd=PASS")
output = open("l-file01.jpg","wb")
output.write(resource.read())
output.close()
Any other solutions?
The url is not the real image, but the url retrieves the image.

When I look in to the code i see only this

Code: Select all

<html><body><img src="../snapPic/Snap_20160331-143832.jpg"/></body></html>

Thanks in advance

Re: Retrieve JPG from url

Posted: Thu Mar 31, 2016 12:30 pm
by scotty101
It seems like urllib.urlretrieve might solve your problems

See here http://stackoverflow.com/questions/3042 ... and-python

Re: Retrieve JPG from url

Posted: Thu Mar 31, 2016 1:15 pm
by mysen

Code: Select all

import subprocess

subprocess.call("wget http://192.168.0.184:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=USER&pwd=PASS", shell=True)
This code will open the command line and enter what you need to down load it. You may run into permission errors though in which case you might have to use this:

Code: Select all

import subprocess

subprocess.call("sudo -r root wget http://192.168.0.184:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=USER&pwd=PASS", shell=True)
and add whatever users name to the sudoers list... MASSIVE SECURITY RISK THOUGH.

Re: Retrieve JPG from url

Posted: Fri Apr 01, 2016 9:12 am
by dverleysen
Hey, thanks for the reply's, i used this code to retrieve the url.

Code: Select all

import urllib2
from bs4 import BeautifulSoup

url = 'http://192.168.0.184:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=USER&pwd=PASS'
html = urllib2.urlopen(url)
soup = BeautifulSoup(html, "html5lib")
imgs = soup.findAll("img")
print imgs
print imgs[1:]
As result from print imgs i get [<img src="../snapPic/Snap_20160401-110642.jpg"/>]
I want to cut the unwanted characters from this string so i try to use for eg. print imgs[1:] but as result i get []

Any tips or solutions?
I want to rebuild the imgs string to the correct image url
imgs string = <img src="../snapPic/Snap_20160401-110642.jpg"/>
wanted result = http://192.168.0.184:88/snapPic/Snap_20 ... 110642.jpg

Re: Retrieve JPG from url

Posted: Fri Apr 01, 2016 10:56 am
by dverleysen
Found a solution here
http://stackoverflow.com/questions/3635 ... esnt-works
Thanks for your help