国产探花免费观看_亚洲丰满少妇自慰呻吟_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://www.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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邛崃市| 自贡市| 溧阳市| 鹤山市| 黑山县| 航空| 汉川市| 山西省| 攀枝花市| 宁阳县| 阿克苏市| 甘肃省| 屯昌县| 乌恰县| 滦平县| 盱眙县| 灵璧县| 广东省| 奉化市| 恩施市| 久治县| 苍溪县| 卢氏县| 德兴市| 红桥区| 万宁市| 双柏县| 四子王旗| 乌鲁木齐县| 嘉定区| 三门县| 湾仔区| 东乡族自治县| 邻水| 龙胜| 固原市| 陆河县| 邢台县| 郁南县| 乐平市| 通渭县|