python抓京东手机数据

上微信头条,,C币就是你的CSDN社区之星徐宜生:爱分享、爱极客! 最流行的语言想学就学写博文,传代码,赚C币

python抓京东手机数据

分类:【python】

pythonphone

python抓京东手机数据

作者:vpoet

日期:大约在夏季

#coding=utf-8import urllib2from lxml import etreeimport reif __name__ == '__main__':main_url = """?keyword=%%E6%%89%%8B%%E6%%9C%%BA&enc=utf-8&suggest=0#keyword=%%E6%%89%%8B%%E6%%9C%%BA&enc=utf-8&qrst=1&ps=addr&rt=1&stop=1&sttr=1&cid3=655&click=3-655&psort=3&page=%s"""page_num = 1for page in range(page_num):html_url = main_url % pageRes = urllib2.urlopen(html_url)Htm = Res.read()#print Htmtree = etree.HTML(Htm);#phone_names = tree.xpath("//div[@id='plist']/ul/li/div[@class='lh-wrap']/div[@class='p-name']/a/text()")#x = 1#for phone_name in phone_names:#print phone_name+'\t'+str(x)+'\n'#x=x+1#phone_pic_urls = tree.xpath("//div[@class='lh-wrap']/div[@class='p-img']/a/img")#for phone_pic_url in phone_pic_urls:#print phone_pic_url.values()[3]#phone_prices = tree.xpath("//div[@class='p-price']/strong") phone_prices = tree.xpath("//*[@id='plist']/ul[@class='list-h clearfix']/li/div/div[@class='p-price']/strong")x = 1for phone_price in phone_prices:print phone_price.values()[1]+'\t'+str(x)+'\n'x = x + 1#phone_comments = tree.xpath("//div[@class='extra']/a/text()")#for phone_comment in phone_comments:#print "评价数"#comment_num = re.findall(r'.{2}(\d+).{3}',phone_comment)#print comment_num[0]#phone_good_comments = tree.xpath("//div[@class='extra']/span[@class='reputation']/text()")#for phone_good_comment in phone_good_comments:#print "好评率"#comment_good_num = re.findall(r'\((\d{2})%.{2}\)',phone_good_comment)#print comment_good_num[0]print "over"

这个没写完,贴出来供大家参考。

上一篇python使用post登陆电子科大信息门户并保存登陆后页面下一篇解决mongodb连接失败问题

顶0踩0

主题推荐猜你在找

查看评论

* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

核心技术类目

要永不言弃坚持到底百折不挠宁死不屈,但我们好多人没想过,

python抓京东手机数据

相关文章:

你感兴趣的文章:

标签云: