爬虫之数据提取: 概述
1. 响应内容的分类
在发送请求获取响应之后,可能存在多种不同类型的响应内容;而且很多时候,我们只需要响应内容中的一部分数据
-
结构化的响应内容
-
json字符串
-
可以使用re、json等模块来提取特定数据
-
-
-
-
- json字符串的例子如下图
![]()
- json字符串的例子如下图
-
-
-
- 可以使用re、lxml等模块来提取特定数据
-
-
-
-
<bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
-
-
-
- html字符串
-
-
- 可以使用re、lxml等模块来提取特定数据
-
2.1 认识xml
xml是一种可扩展标记语言,样子和html很像,功能更专注于对传输和存储数据
<bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
上面的xml内容可以表示为下面的树结构:

-
-
超文本标记语言
-
为了更好的显示数据,侧重点是为了显示
-
-
xml:
-
可扩展标记语言
-
-

具体生产环境中,re模块性能最好,lxml模块性能中等,beautifulsoup性能较差.
虽然beatifulsoup功能强大,但是性能较差




浙公网安备 33010602011771号