码迷,mamicode.com
首页 > 编程语言 > 详细

python3用BeautifulSoup抓取a标签

时间:2016-11-13 22:35:53      阅读:468      评论:0      收藏:0      [点我收藏+]

标签:dal   urllib   pytho   find   port   int   htm   python3   .com   

# -*- 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=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标签

标签:dal   urllib   pytho   find   port   int   htm   python3   .com   

原文地址:http://www.cnblogs.com/dengyg200891/p/6059865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!