Python xml 解析百度糯米信息
先利用爬虫利用百度糯米提供的api来采集北京当天的团购信息,保存为numi.html
import xml.etree.ElementTree as ET
import os
class Nuomi():
def __init__(self):
self.numi=[]
def Parse(self,filepath):
tree=ET.parse(filepath)
root =tree.getroot()
for url in root.iter('url'):
nuomi_lei={}
data=url.find('data')
if data is not None:
display=data.find('display')
if display is not None:
try:
nuomi_lei['title']=display.find('title').text
except Exception as e:
print("No title")
try:
nuomi_lei['businessTitle']=display.find('businessTitle').text
except Exception as e:
print ("No businessTitle")
try:
nuomi_lei['value'] =display.find('value').text
except Exception as e:
print ("No value")
try:
nuomi_lei['price']=float(display.find('price').text)
except Exception as e:
print("No pire")
self.numi.append(nuomi_lei)
return(self.numi)
if __name__ == '__main__':
nuomi=Nuomi()
date=nuomi.Parse('numi.html')
print(len(date))
相关文章
- Python正则表达式指南
- Python处理PDF及生成多层PDF
- 在Python中读取MATLAB的数据文件
- 百度攻城狮训练营2021-工程能力study2 -- 2.4 代码检查规则:Python 语言案例详解 脑图整理
- python学习之下载百度搜索到的图片(含源代码)
- 用python实现的百度新歌榜、热歌榜下载器
- Python heapq实现大顶堆
- Python——项目开发中常用的精华Python库介绍与整理.
- Python实现将坐标点绘制到地图上
- 【百度领航团】小白零基础python学习笔记
- 【Python爬虫】:爬取(谷歌/百度/搜狗)的搜索结果
- 【数据结构】:链表(Python实现)
- Python判断一个字符串中是否存在多个子串中的一个
- python第三十课--异常(else讲解)
- Python Solve UnicodeEncodeError 'gbk' / 'ascii' / 'utf8' codec can't encode character 'x??' in position ? 解决有关Python编码的错误
- 【图像处理】——Python实现图像特征提取&BP神经网络实现图像二分类
- [Python]迭代器生成器 随手记
- Python 创建和使用类