这篇文章主要介绍了python 3利用beautifulsoup抓取p标签的方法,文中给出了详细的示例代码供大家参考学习,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
前言
本文主要介绍的是关于python 3用BeautifulSoup抓取p标签的方法示例,分享出来供大家参考学习,下面来看看详细的介绍:
示例代码:
# -*- 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的p for k in soup.find_all('p',class_='atcTit_more'):#,string='更多' print(k) #【相关推荐】
立即学习“Python免费学习笔记(深入)”;











