Download unnamed web image?

John Bokma john at castleamber.com
Tue Feb 16 20:48:11 EST 2010


galileo228 <mattbarkan at gmail.com> writes:

> Using BeautifulSoup, mechanize, and urllib, I've constructed the
> following:
>
> br.open("http://www.school.edu/students/facebook/")
> br.select_form(nr = 1)
>
> br.form['fulltextsearch'] = 'msb83' # this searches the facebook for
> me
> br.submit()
> results = br.response().read()
> soup = BeautifulSoup(results)
> foo2 = soup.find('td', attrs={'width':'95'})
> foo3 = foo2.find('a')
> foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'})
> # this just drills down to the <img> line and   until this point the
> program does not return an error
>
> save_as = os.path.join('./', msb83 + '.jpg')
> urllib.urlretrieve(foo4, save_as)
>
> I get the following error msg after running this code:
>
> AttributeError: 'NoneType' object has no attribute 'strip'

Wild guess, since you didn't provide line numbers, etc.

foo4 is None

(I also would like to suggest to use more meaningful names)

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development



More information about the Python-list mailing list