Python Beautifulsoup img tag parsing

后端 未结 6 1514
旧巷少年郎
旧巷少年郎 2021-01-06 02:48

I am using beautifulsoup to parse all img tags which is present in \'www.youtube.com\'

The code is

import urllib2
from BeautifulSoup import Beautiful         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 03:31

    in my case some images didn't contain src.

    so i did this to avoid keyError exception:

    art_imgs = set(img['src'] for img in article.find_all('img') if img.has_attr('src')) 
    

提交回复
热议问题