Python Beautifulsoup img tag parsing

后端 未结 6 1557
旧巷少年郎
旧巷少年郎 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:34

    I had the similar problem. I couldn't find all images. So here is the piece of code that will give you any attribute value of an image tag.

    from BeautifulSoup import BeautifulSoup as BSHTML
    import urllib2
    page = urllib2.urlopen('http://www.youtube.com/')
    soup = BSHTML(page)
    images = soup.findAll('img')
    for image in images:
        #print image source
        print image['src']
        #print alternate text
        print image['alt']
    

提交回复
热议问题