Download unnamed web image?

galileo228 mattbarkan at gmail.com
Tue Feb 16 21:40:11 EST 2010


On Feb 16, 8:48 pm, John Bokma <j... at castleamber.com> wrote:
> galileo228 <mattbar... 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


I thought it was too, and I just doublechecked.  It's actually

foo3 = foo2.find('a')

that is causing the NoneType error.

Thoughts?



More information about the Python-list mailing list