473,670 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fetching images from web?

hi, i want to automate some tasks of gathering photos from web, i tried
urllib/urllib2, both ended up without much success (saved gifs with
only a border, nothing else)..

the code i used was:
data = urllib2.urlopen ("http://aspn.activestat e.com/ASPN/img/komodo_aspn_oth er.gif") #was looking through cookbook, so i used that as a sample image
data = data.read()
file = open("f:/test.gif", "w")
file.write(data )
file.close()

can someone suggest a better way (or what's wrong with urllib/urllib2)?
thanks alot!

Dec 28 '05 #1
5 2025
ra********@gmai l.com writes:
hi, i want to automate some tasks of gathering photos from web, i tried
urllib/urllib2, both ended up without much success (saved gifs with
only a border, nothing else)..
Um - what else did you expect? You fetched a gif, you should get a gif.
the code i used was:
data = urllib2.urlopen ("http://aspn.activestat e.com/ASPN/img/komodo_aspn_oth er.gif") #was looking through cookbook, so i used that as a sample image
data = data.read()
file = open("f:/test.gif", "w")
file.write(data )
file.close()

This looks like it works fine to me.
can someone suggest a better way (or what's wrong with urllib/urllib2)?
thanks alot!


Can you be more explicit about what you think is wrong with what
you're doing?

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Dec 28 '05 #2
<ra********@gma il.com> wrote:
hi, i want to automate some tasks of gathering photos from web, i tried
urllib/urllib2, both ended up without much success (saved gifs with
only a border, nothing else)..

the code i used was:
data = urllib2.urlopen ( "http://aspn.activestat e.com/ASPN/img/komodo_aspn_oth er.gif") #was looking through cookbook, so i used that as a sample image
data = data.read()
file = open("f:/test.gif", "w")


Since you appear to want to write binary data, you should use 'wb', not
'w', as the "mode".
Alex
Dec 28 '05 #3
ah, wb works :D thanks alot!

Dec 28 '05 #4
may be using wget/curl but then it is no longer python ;-)

ra********@gmai l.com wrote:
hi, i want to automate some tasks of gathering photos from web, i tried
urllib/urllib2, both ended up without much success (saved gifs with
only a border, nothing else)..

the code i used was:
data = urllib2.urlopen ("http://aspn.activestat e.com/ASPN/img/komodo_aspn_oth er.gif") #was looking through cookbook, so i used that as a sample image
data = data.read()
file = open("f:/test.gif", "w")
file.write(data )
file.close()

can someone suggest a better way (or what's wrong with urllib/urllib2)?
thanks alot!


Dec 28 '05 #5
ra********@gmai l.com wrote:
hi, i want to automate some tasks of gathering photos from web, i tried
urllib/urllib2, both ended up without much success (saved gifs with
only a border, nothing else)..

the code i used was:

data = urllib2.urlopen ("http://aspn.activestat e.com/ASPN/img/komodo_aspn_oth er.gif") #was looking through cookbook, so i used that as a sample image
data = data.read()
file = open("f:/test.gif", "w")
file.write( data)
file.close( )


can someone suggest a better way (or what's wrong with urllib/urllib2)?
thanks alot!

fetching images from web is my little hobby (but i dont know, if you
want fetch this kind of images). i sending my little script.

import urllib
for i in range(25,286,1) :
if i<100: n='0'+str(i)
else: n=str(i)
for j in range(16):
if j<10: o='0'+str(j)
else: o=str(j)
s='used for error detecting'
url='http://www.paradisetoo ns.com/ima/toon'+str(i)+'/p'+str(j)+'.jpg '
fil='e:/pics/xxz37/prtn_'+n+'_'+o+ '.jpg'
try:
s=urllib.urlope n(url).readline (6)
except:
print ''
if s.lower()=='<ht ml>':
print 'file '+url+' does not exist'
else:
print 'downloading file: '+url
urllib.urlretri eve(url,fil)

any sugestions for doing this better?
Dec 28 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1913
by: C3 | last post by:
Hi everone. I'm trying to write a shell script that fetches a number of images from a map website (www.whereis.com.au). Basically, the page asks you for a street address and then queries the server in a strange way, and then displays the map you asked for. It then allows you to scroll in different directions from that map. My aim is to be able to write a program that will take a street address, query the website, and return the...
0
1698
by: Shujun Huang | last post by:
Hi, I am working on converting Informix database to Postgre. I have one question for fetching records using PostgreSQL. The record I am fetching is a variable size text string. Before fetching the record, a preallocated static buffer size will have to be declared beforehand in the declaration section. Since the record sizes vary a lot, instead of using the static buffer, is there a dynamic way to fetch these records? Informix (Oracle...
2
1292
by: VivekR | last post by:
Hi All Please help me out with this thing in javascript. I am dumb in the world of JS/Html/... I have a url, say www.someurl.com. It has a list of jpgs that can accessed as www.something.com/one.jpg or www..../two.jpg etc. Now i need to get the list of the jpgs and then display it on a web page one by one, triggered by a timer. I have to do this using javascript.
22
2699
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other things. So, in instances where I list, for example, the latest weblogs. I list the headline of the weblog, the date and the name of the member who wrote it. Now, the name isn't just "Smith", but rather Smith's online status, his nick and his...
1
1420
by: ProjectGoldfish | last post by:
Currently im taking this old piece of code $fileName = $_GET; $full = $_GET; $ext = substr(strrchr($fileName, "."), 1); $path = "../../../include/images/mini/"; if($full) $path = "../../../include/images/full/"; else $path = "../../../include/images/mini/";
5
2974
by: Bhavesh | last post by:
Hello genious people, I m trying to insert a LARGE text from Multiline Textbox into my table of sqlserver2000. I m using vs-2005. Please note that I dont want to store blob data From FILE TO TABLE, like storing IMAGE into DB.
1
1817
by: Bhavesh | last post by:
Hi Bruce, Thanks For Reply. U were right, Needed to pass string , but also need to pass size of Data( instead of 16, passed actual length of data). So that worked for me & didn't get any error. But now problem in fetching, not able to fetch data from table correctly. Here is my code. I hav following problems with this coding
0
1287
by: punitshrivastava | last post by:
Hi to All Senior's, I am working in Asp.net with C#. I am newbie in C#. So i want to fetch mutiple images from database .Database i am using is Sql Server. For this i code: //get the image id from the url string Imagename = DropDownList1.SelectedItem .Text ; //string Imagename = Request.QueryString; //build our query statementworkstation id=SOFTWARE3;packet size=4096;integrated security=SSPI;data source=SOFTWARE3;persist security...
2
2672
by: SunshineInTheRain | last post by:
I'm trying to modify a long long code within a button click by make the insert/update/delete/select using the same transaction. Purpose is to make sure every operation can be rollback instead of some table inserted but some not. But I get this error: The SqlCommand is currently busy Open, Fetching. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5686
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.