I am pretty new with BeautifulSoup
. I am trying to print image links from http://www.bing.com/images?q=owl:
redditFile = urllib2.urlopen("http://www.bing.com/images?q=owl")
redditHtml = redditFile.read()
redditFile.close()
soup = BeautifulSoup(redditHtml)
productDivs = soup.findAll('div', attrs={'class' : 'dg_u'})
for div in productDivs:
print div.find('a')['t1'] #works fine
print div.find('img')['src'] #This getting issue KeyError: 'src'
But this gives only title, not the image source Is there anything wrong?
Edit: I have edited my source, still could not get image url.
Bing is using some techniques to block automated scrapers. I tried to print
and found that they are sending source in attribute names src2, so following should work -
This is working for me. Hope it helps.