网络爬虫:Requests+lxml
来源:互联网 发布:sql 字符串中有单引号 编辑:程序博客网 时间:2024/05/14 13:09
比较常用
# -*-coding:utf8-*-import requestsfrom lxml import etreeurl="http://econpy.pythonanywhere.com/ex/001.html"page=requests.get(url)html=page.textselector = etree.HTML(html)buyer=selector.xpath('//div[@title="buyer-name"]/text()')prices=selector.xpath('//span[@class="item-price"]/text()')print (buyer)print (prices)
这个用的少一些
# -*-coding:utf8-*-import requestsfrom lxml import htmlurl="http://econpy.pythonanywhere.com/ex/001.html"page=requests.get(url)tree=html.fromstring(page.text)buyer=tree.xpath('//div[@title="buyer-name"]/text()')prices=tree.xpath('//span[@class="item-price"]/text()')print (buyer)print (prices)
- Xpath的语法参考
http://www.w3school.com.cn/xpath/xpath_syntax.asp - Chrome中使用时可以下载插件:Xpath helper
- 参考使用requests和lxml编写python爬虫小记
http://www.tuicool.com/articles/vABNRbR
XPath在python中的高级应用
参见:http://blog.csdn.net/winterto1990/article/details/47903653
但是遇到中文网页时,中文出现乱码。
req = requests.get("http://news.sina.com.cn/")print (req.text)
为了解决这个问题,请参考这篇文章:
http://blog.csdn.net/chaowanghn/article/details/54889835
0 0
- 网络爬虫:Requests+lxml
- 网络爬虫之lxml
- requests库---网络爬虫
- re+lxml+requests基础知识
- pip、lxml、requests安装
- 从零开始学网络爬虫之Requests库
- Python网络爬虫之Requests库
- python网络爬虫1.1requests库
- python爬虫之lxml
- XPATH(lxml)爬虫测试
- 爬虫系列14.Lxml
- python爬虫 - python requests网络请求简洁之道
- 使用requests+beautifulsoup模块实现python网络爬虫功能
- 网络爬虫之requests库中两个重要的对象
- 1、网络爬虫之规则之requests库入门
- Python网络爬虫requests、bs4爬取空姐网图片
- Python网络爬虫——Requests第三方库
- 网络爬虫系列笔记(2)——Requests库
- parser.parse is not a function——arcgis api报错解决办法
- 结构体类型作为函数参数
- SQL Server中获取第一天和最后一天
- 拆分多个字符串放入对应的容器程序代码
- cn.bing.com
- 网络爬虫:Requests+lxml
- 什么是脏读,不可重复读,幻读
- 启动redis出现Creating Server TCP listening socket *:6379: bind: No such file or directory
- Html Select 使用selected属性设置默认选择项
- 转:Cracking Sublime Text 3
- C语言学习
- Numpy : ndarray切片索引
- HashMap与Hashtable的区别
- Elasticsearch 分布式原理