Python Beautifulsoup img tag parsing

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

    Seems to work when I try it here

    import urllib2
    from BeautifulSoup import BeautifulSoup
    page = urllib2.urlopen('http://www.youtube.com/')
    soup = BeautifulSoup(page)
    tags=soup.findAll('img')
    print "\n".join(set(tag['src'] for tag in tags))
    

    Produces this which looks OK to me

    http://i1.ytimg.com/vi/D9Zg67r9q9g/market_thumb.jpg?v=723c8e
    http://s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif
    //s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif
    /gen_204?a=fvhr&v=mha7pAOfqt4&nocache=1337083207.97
    http://i3.ytimg.com/vi/fNs8mf2OdkU/market_thumb.jpg?v=4f85544b
    http://i4.ytimg.com/vi/CkQFjyZCq4M/market_thumb.jpg?v=4f95762c
    http://i3.ytimg.com/vi/fzD5gAecqdM/market_thumb.jpg?v=b0cabf
    http://i3.ytimg.com/vi/2M3pb2_R2Ng/market_thumb.jpg?v=4f0d95fa
    //i2.ytimg.com/vi/mha7pAOfqt4/hqdefault.jpg
    

提交回复
热议问题