File: _web_example3.py

package info (click to toggle)
nodebox-web 1.9.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,900 kB
  • sloc: python: 7,582; ansic: 581; xml: 239; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Querying Yahoo!

import web

# Get a list of links for a search query.
links = web.yahoo.search_images("food")
print links

# Retrieve a random image.
img = web.url.retrieve(links)

# We can't always trust the validity of data from the web,
# the site may be down, the image removed, etc.
# If you're going to do a lot of batch operations and
# you don't want the script to halt on an error,
# put your code inside a try/except statement.
try:
    data=img.data
except:
    print str(img.error)
    
# An easier command is web.download():
img = web.download(links)