前言
本文主要介绍的是关于python 3用BeautifulSoup抓取div标签的方法示例,分享出来供大家参考学习,下面来看看详细的介绍:
示例代码:
# -*- coding:utf-8 -*- #python 2.7 #XiaoDeng #http://tieba.baidu.com/p/2460150866 #标签操作 from bs4 import BeautifulSoup import urllib.request import re #如果是网址,可以用这个办法来读取网页 #html_doc = "http://tieba.baidu.com/p/2460150866" #req = urllib.request.Request(html_doc) #webpage = urllib.request.urlopen(req) #html = webpage.read() html="""The Dormouse's story The Dormouse's story
once upon a time there were three little sisters; and their names were , Lacie and Tillie; Lacie and they lived at the bottom of a well.
加载中… 个人资料
- 博客等级:
- 博客积分:0
- 博客访问:3,971
- 关注人气:0
- 获赠金笔:0支
- 赠出金笔:0支
- 荣誉徽章:
...
""" soup = BeautifulSoup(html, 'html.parser') #文档对象 # 类名为xxx而且文本内容为hahaha的div for k in soup.find_all('div',class_='atcTit_more'):#,string='更多' print(k) #更多>>总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家考高分网的支持。



