首页 > 代码库 > python3用BeautifulSoup抓取a标签

python3用BeautifulSoup抓取a标签

# -*- coding:utf-8 -*-
#python 2.7
#XiaoDeng
#http://tieba.baidu.com/p/2460150866


from bs4 import BeautifulSoup
import urllib.request


html_doc = "http://tieba.baidu.com/p/2460150866"
req = urllib.request.Request(html_doc)  
webpage = urllib.request.urlopen(req)  
html = webpage.read()


soup = BeautifulSoup(html, html.parser)


#抓取class=‘app_icon_link‘的a标签
img_src=http://www.mamicode.com/soup.findAll("a",{class:app_icon_link})   #抓取a标签
for img in img_src:
    img=img.findAll(img)
    for k in img:
        k=k.get(src)
        print(k)

 

python3用BeautifulSoup抓取a标签