Python获取网页内容、使用BeautifulSoup库分析html
来源:互联网 发布:帝国cms支付 编辑:程序博客网 时间:2024/06/04 20:09
利用 urllib包 获取网页内容
#引入包from urllib.request import urlopenresponse = urlopen("http://fund.eastmoney.com/fund.html")html = response.read();#这个网页编码是gb2312#print(html.decode("gb2312"))#把html内容保存到一个文件with open("1.txt","wb") as f: f.write(html.decode("gb2312").encode("utf8")) f.close()
使用BeautifulSoup分析html
from bs4 import BeautifulSoup# 读取文件内容with open("1.txt", "rb") as f: html = f.read().decode("utf8") f.close()# 分析html内容soup = BeautifulSoup(html,"html.parser")# 取出网页titleprint(soup.title) #<title>每日开放式基金净值表 _ 天天基金网</title># 基金编码codes = soup.find("table",id="oTable").tbody.find_all("td","bzdm")result = () # 初始化一个元组for code in codes: result += ({ "code":code.get_text(), "name":code.next_sibling.find("a").get_text(), "NAV":code.next_sibling.next_sibling.get_text(), "ACCNAV":code.next_sibling.next_sibling.next_sibling.get_text() },)# 打印结果print(result[0]["name"])
阅读全文
0 0
- Python获取网页内容、使用BeautifulSoup库分析html
- Python获取网页指定内容(BeautifulSoup工具的使用方法)
- Python使用BeautifulSoup提取特定HTML标签内容
- [Python下载CSDN博客]2. 使用BeautifulSoup分析HTML(一)
- [Python下载CSDN博客]2. 使用BeautifulSoup分析HTML(二)
- python beautifulsoup 抓取网页正文内容
- 使用XPath解析HTML获取网页内容
- python : BeautifulSoup 网页HTML 解析器
- python beautifulsoup多线程分析抓取网页
- python beautifulsoup多线程分析抓取网页
- 用python的BeautifulSoup分析html
- 用python的BeautifulSoup分析html
- [学习]用python的BeautifulSoup分析html
- 用python的BeautifulSoup分析html
- 用python的BeautifulSoup分析html
- 学习]用python的BeautifulSoup分析html
- Python:[转]浅学BeautifulSoup分析html
- Python 获取网页内容
- 数据结构基础概念篇
- 软件工程之设计模式
- 九九乘法表
- Ruby学习笔记(21)_限制权限
- 数组去重
- Python获取网页内容、使用BeautifulSoup库分析html
- Android SeekBar去掉左右两边空隙
- golang知识点整理(持续更新)
- 用户用浏览器访问一个网站,发生了什么。
- 高德地图不显示问题
- 【Dlib】在项目中同时导入Dlib库和OpenCV库
- Effective Java
- android 客户端学习-给button按钮设置圆角
- poj3041-Asteroids(最小点覆盖,最大匹配)