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

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

網絡爬蟲:Requests+lxml

2019-11-14 12:00:31
字體:
來源:轉載
供稿:網友

比較常用

# -*-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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苗栗县| 双鸭山市| 南阳市| 德江县| 乌拉特前旗| 云安县| 宿州市| 弥渡县| 德化县| 左贡县| 玉溪市| 剑河县| 高邑县| 江城| 资中县| 江陵县| 通化市| 毕节市| 宝坻区| 罗江县| 房山区| 保康县| 米林县| 肃南| 惠安县| 察雅县| 南溪县| 武隆县| 高要市| 英德市| 诸暨市| 手游| 镇沅| 靖西县| 兖州市| 莆田市| 蓝山县| 九龙县| 高要市| 金山区| 金山区|