python爬虫获取标签_python爬虫:用BeautifulSoup抓取div标签

1 #-*- coding:utf-8 -*-

2 #python 2.7

3 #XiaoDeng

4 #http://tieba.baidu.com/p/2460150866

5 #标签操作

6

7

8 from bs4 importBeautifulSoup9 importurllib.request10 importre11

12

13 #如果是网址,可以用这个办法来读取网页

14 #html_doc = "http://tieba.baidu.com/p/2460150866"

15 #req = urllib.request.Request(html_doc)

16 #webpage = urllib.request.urlopen(req)

17 #html = webpage.read()

18

19

20

21 html="""

22

The Dormouse's story23 24

The Dormouse's story

25

Once upon a time there were three little sisters; and their names were26 ,27 Lacie and28 Tillie;29 Lacie30 and they lived at the bottom of a well.

31
loading.gif加载中…
32

33

34 个人资料35 36 37
38
  • 39
  • 博客等级:sg_trans.gif40
  • 博客积分:041
42
  • 43
  • 博客访问:3,97144
  • 关注人气:045
  • 获赠金笔:0支46
  • 赠出金笔:0支47
  • 荣誉徽章:48
49
50 51

...

52 """

53 soup = BeautifulSoup(html, 'html.parser') #文档对象

54

55

56

57 #类名为xxx而且文本内容为hahaha的div

58 for k in soup.find_all('div',class_='atcTit_more'):#,string='更多'

59 print(k)60 #

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值