Python Beautifulsoup img tag parsing

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

    def grabimagetags():
    import urllib2
    from BeautifulSoup import BeautifulSoup
    page = urllib2.urlopen('http://www.youtube.com/')
    soup = BeautifulSoup(page)
    tags = soup.findAll('img')
    list.extend(set(tag['src'] for tag in tags))
    
    
    return list
    

    grabimagetags()

    i would only make this change so that you can pass the list of img tags

提交回复
热议问题