国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

網絡爬蟲:Requests+lxml

2019-11-14 11:29:42
字體:
來源:轉載
供稿:網友

比較常用

# -*-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()')這個用的少一些

# -*-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://m.survivalescaperooms.com.cn/xpath/xpath_syntax.
aspChrome中使用時可以下載插件: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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丹寨县| 天全县| 蒙自县| 灯塔市| 永平县| 泰来县| 云南省| 文化| 益阳市| 德格县| 稻城县| 武宁县| 濉溪县| 清徐县| 西充县| 龙泉市| 承德市| 青川县| 迁西县| 贡觉县| 新河县| 平江县| 白银市| 仁怀市| 田东县| 新蔡县| 林甸县| 全椒县| 河间市| 剑川县| 子洲县| 简阳市| 阿拉善左旗| 石渠县| 枞阳县| 会昌县| 吴旗县| 青冈县| 喀喇| 周至县| 安乡县|