Beautiful Soup的使用
来源:互联网 发布:centos debian 稳定性 编辑:程序博客网 时间:2024/05/22 12:53
# coding:utf8from bs4 import BeautifulSoupimport rehtml_doc = """<html><head><title>The Dormouse's story</title></head><body><p class="title"><b>The Dormouse's story</b></p><p class="story">Once upon a time there were three little sisters; and their names were<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;and they lived at the bottom of a well.</p><p class="story">...</p>"""soup = BeautifulSoup(html_doc,'html.parser',from_encoding='utf-8')print('获取所有的链接')links = soup.find_all('a')for link in links: print(link.name+link['href']+link.get_text())print('获取lacie的链接')link_node = soup.find('a',href='http://example.com/lacie')print(link_node.name+link_node['href']+link_node.get_text())print('正则匹配')link_node = soup.find('a',href=re.compile(r'ill'))print(link_node.name+link_node['href']+link_node.get_text())print('获取p段落文字')#因为class是关键字所以要加个下划线p_node = soup.find('p',class_='title')print(p_node.name+p_node.get_text())
阅读全文
0 0
- Beautiful Soup的使用
- Beautiful Soup的使用
- Beautiful Soup的安装和使用
- Beautiful Soup使用
- Beautiful Soup 使用总结
- Beautiful Soup使用介绍
- Beautiful Soup的用法
- Beautiful Soup 的用法
- Beautiful Soup的用法
- 使用Beautiful Soup进行查找
- 使用Beautiful Soup解析dom
- Python中使用Beautiful Soup库的超详细教程
- Python中使用Beautiful Soup库的超详细教程
- Python中使用Beautiful Soup库的超详细教程
- Python爬虫之Beautiful Soup库的安装与使用
- 【python学习笔记】10:Beautiful Soup模块的使用
- Python中-Beautiful Soup库的基本使用
- Python中使用Beautiful Soup库的超详细教程
- centos 7.3 设置静态IP或ping 报name or service not known
- 最新管家婆财贸双全.NET V17.0免狗破解
- 用java打包成jar可执行文件并执行windows定时任务
- 手动makecpb的方法
- Duplicate files copied in APK META-INF/
- Beautiful Soup的使用
- JZOJ 5405. 【NOIP2017提高A组模拟10.10】Permutation
- redis学习系列(三-1)--redis基础类型初探(字符串)
- Kafka架构和原理深度剖析
- ubuntu黑屏的原因
- Spring Boot的每个模块包详解
- cookie 和session 的区别详解
- 逆序输出
- Linux网络编程入门必备函数说明