我很新,BeautifulSoup
。我想從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'
但這僅給出標題,而不是圖像源 這有什麼錯?
編輯: 我編輯了我的源代碼,仍然無法獲取圖像url。
謝謝!也很有趣。你怎麼知道他們發送的源代碼是'src2' – nlper
正如我所說的,我嘗試過'print div.find('img')',它打印了整個img標籤的html。 –
感謝任何負責人http://stackoverflow.com/questions/30734483/get-div-attribute-val-and-div-text-body – nlper