dverleysen
Posts: 34
Joined: Wed Jan 06, 2016 2:00 pm

Retrieve JPG from url [solved]

Thu Mar 31, 2016 10:46 am

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
Last edited by dverleysen on Fri Apr 01, 2016 10:56 am, edited 3 times in total.
https://www.linkedin.com/pulse/harvesting-tomatoes-version-20-didier-verleysen/

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Retrieve JPG from url

Thu Mar 31, 2016 12:30 pm

It seems like urllib.urlretrieve might solve your problems

See here http://stackoverflow.com/questions/3042 ... and-python
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

mysen
Posts: 13
Joined: Sun Feb 21, 2016 11:49 pm

Re: Retrieve JPG from url

Thu Mar 31, 2016 1:15 pm

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.

dverleysen
Posts: 34
Joined: Wed Jan 06, 2016 2:00 pm

Re: Retrieve JPG from url

Fri Apr 01, 2016 9:12 am

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
https://www.linkedin.com/pulse/harvesting-tomatoes-version-20-didier-verleysen/

dverleysen
Posts: 34
Joined: Wed Jan 06, 2016 2:00 pm

Re: Retrieve JPG from url

Fri Apr 01, 2016 10:56 am

Found a solution here
http://stackoverflow.com/questions/3635 ... esnt-works
Thanks for your help
https://www.linkedin.com/pulse/harvesting-tomatoes-version-20-didier-verleysen/

Return to “Python”