饿了么外卖网站是一个ajax动态加载的网站

Version1:直接页面提取

from lxml importetreeimportrequestsimportsysimporttime

reload(sys)

sys.setdefaultencoding('utf-8')

url= 'https://www.ele.me/place/ws101hcw982?latitude=22.52721&longitude=113.95232'response=requests.get(url)printresponse.status_code

time.sleep(10)

html=response.content

selector=etree.HTML(html)

rez= selector.xpath('//*[@class="place-rstbox clearfix"]')print 'haha',rez #[]

for i inrez:

Name= i.xpath('//*[@class="rstblock-title"]/text()')printname

msales= i.xpath('//*[@class="rstblock-monthsales"]/text()')

tip= i.xpath('//*[@class="rstblock-cost"]/text()')

stime= i.xpath('//*[@class="rstblock-logo"]/span/text()')print u'店名'

for j inName:printjbreak

问题:根据//*[@class="place-rstbox clearfix"]xpath提取成功,但是rez输出为空

Version2:通过接口提取

geohash=ws101hcw982&latitude=22.52721&longitude=113.95232:位置信息参数及参数值

terminal=web:渠道信息

extras[]=activities和offset=0未知

importrequestsimportjson

url= 'https://www.ele.me/restapi/shopping/restaurants?extras[]=activities&geohash=ws101hcw982&latitude=22.52721&limit=30&longitude=113.95232&offset=0&terminal=web'resp=requests.get(url)printresp.status_code

Jdata=json.loads(resp.text)#print Jdata

for n inJdata:

name= n['name']

msales= n['recent_order_num']

stime= n['order_lead_time']

tip= n['description']

phone= n['phone']print name

输出:原以为通过limit=100就可以提取100条商家信息,然而最多只显示30

Version3:通过selenium提取

from selenium importwebdriverimportselenium.webdriver.support.ui as uiimporttime

driver= webdriver.PhantomJS(executable_path=r"C:\Python27\phantomjs.exe")#driver = webdriver.Chrome()

driver.get('https://www.ele.me/place/ws101hcw982?latitude=22.52721&longitude=113.95232')

time.sleep(10)

driver.get_screenshot_as_file("E:\\Elm_ok.jpg")

wait= ui.WebDriverWait(driver,10)

wait.until(lambda driver: driver.find_element_by_xpath('//div[@class="place-rstbox clearfix"]'))

name= driver.find_element_by_xpath('//*[@class="rstblock-title"]').text

msales= driver.find_element_by_xpath('//*[@class="rstblock-monthsales"]').text

tip= driver.find_element_by_xpath('//*[@class="rstblock-cost"]').text

stime= driver.find_element_by_xpath('//*[@class="rstblock-logo"]/span').textprint name #乐凯撒比萨(生态园店)

注:find_element只提取一个

改进版

#coding=utf-8

from selenium importwebdriverimportselenium.webdriver.support.ui as uiimporttime

driver= webdriver.PhantomJS(executable_path=r"C:\Python27\phantomjs.exe")#driver = webdriver.Chrome()

driver.get('https://www.ele.me/place/ws101hcw982?latitude=22.52721&longitude=113.95232')

time.sleep(10)#driver.get_screenshot_as_file("E:\\Elm_ok.jpg")

wait= ui.WebDriverWait(driver,10)

wait.until(lambda driver: driver.find_element_by_xpath('//div[@class="place-rstbox clearfix"]'))#driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") #滚动至底部页面

defexecute_times(times):for i in range(times + 1):

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

time.sleep(5)

execute_times(20)

name= driver.find_elements_by_xpath('//*[@class="rstblock-title"]')

msales= driver.find_elements_by_xpath('//*[@class="rstblock-monthsales"]')

tip= driver.find_elements_by_xpath('//*[@class="rstblock-cost"]')

stime= driver.find_elements_by_xpath('//*[@class="rstblock-logo"]/span')#print name,msales,stime,tip #[

print type(tip) #

printlen(name) #120for i inname:print i.text

说明:通过execute_times函数,滚动条每下移一次,休息5s,从而使页面加载更多的商家信息

输出:

python爬取饿了么评论_爬虫实例:饿了么爬虫相关推荐

  1. python 爬取亚马逊评论_用Python爬取了三大相亲软件评论区,结果...

    小三:怎么了小二?一副愁眉苦脸的样子. 小二:唉!这不是快过年了吗,家里又催相亲了 ... 小三:现在不是流行网恋吗,你可以试试相亲软件呀. 小二:这玩意靠谱吗? 小三:我也没用过,你自己看看软件评论 ...

  2. python爬取携程酒店信息_不写代码玩转爬虫实例(3) - 抓取携程酒店信息

    背景需求 有不少朋友问永恒君携程网站的酒店信息怎么抓取,今天这篇文章来分享一下使用web scraper来快速实现抓取携程酒店信息. 例如,在携程官网搜索北京 密云水库的酒店信息, 可以搜索到非常多的 ...

  3. python爬取b站评论_学习笔记(1):写了个python爬取B站视频评论的程序

    学习笔记(1):写了个python爬取B站视频评论的程序 import requests import json import os table='fZodR9XQDSUm21yCkr6zBqiveY ...

  4. python爬b站评论_学习笔记(1):写了个python爬取B站视频评论的程序

    学习笔记(1):写了个python爬取B站视频评论的程序 import requests import json import os table='fZodR9XQDSUm21yCkr6zBqiveY ...

  5. python爬取当当网商品评论

    python爬取当当网商品评论 本案例获取某鞋评论作为例 案例目的: 通过爬取当当网商品评价,介绍通过结合jsonpath和正则表达式获取目标数据的方法. 代码功能: 输入爬取的页数,自动下载保存每页 ...

  6. python爬取苏宁商品评论

    python爬取苏宁商品评论 爬取其他电商物品评论的案例如下: https://blog.csdn.net/coffeetogether/article/details/114296159 https ...

  7. python爬取网易云音乐评论分析_python爬取网易云音乐评论

    本文实例为大家分享了python爬取网易云音乐评论的具体代码,供大家参考,具体内容如下 import requests import bs4 import json def get_hot_comme ...

  8. python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜 python爬取网易云音乐热歌榜实例代码...

    想了解python爬取网易云音乐热歌榜实例代码的相关内容吗,FXL在本文为您仔细讲解python爬取网易云音乐热歌榜的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:python,网易热歌榜 ...

  9. python 爬取菜鸟教程python100题,百度贴吧图片反爬虫下载,批量下载

    每天一点点,记录学习 python 爬取菜鸟教程python100题 近期爬虫项目,看完请点赞哦: 1:python 爬取菜鸟教程python100题,百度贴吧图片反爬虫下载,批量下载 2:pytho ...

  10. 【爬虫】Python爬取电商平台评论完整代码

    利用Ajax爬取淘宝评论,这里完整的补充一下,包括数据存储. 对于Ajax参数的分析,Python爬取平台评论,这篇文章分析过了这里不再重复了. 主要是完善一下代码. import time impo ...

最新文章

  1. 启动controller节点nova组件服务,报错ERROR 13
  2. 韩国讨论到 2020 年拥抱开源操作系统
  3. 将一个键值对添加入一个对象_细品Redis高性能数据结构之hash对象
  4. 排序和去重--说说两个简单常用的算法
  5. 他毕业于北师大,编写了我国首套数学教材,陈景润华罗庚都崇拜他
  6. 【年度重磅】《2021营销自动化应用基准报告》正式发布!
  7. 使用tcl文件分配管脚
  8. 【python工具】获取linux和windows系统指定接口的IP地址
  9. ontological 词根词缀_词根的魅力
  10. pytorch中加入注意力机制(CBAM),以ResNet为例。到底要不要用ImageNet预训练?如何加预训练参数?
  11. 【Js】JavaScript数据类型隐式转换
  12. 成功制定:会议纪要模板
  13. win8无权限访问这台计算机,win8电脑IPv4显示无internet访问权限的解决方法
  14. 计算机应用技术专业就业方向分析
  15. c语言 椭圆,C语言画圆椭圆
  16. ASP.NET上传一个文件夹
  17. C+++实现推箱子(附加回撤功能)
  18. 【Web技术】919- 前端关于单点登录的知识
  19. Small Tip: 怎么去Schedule一个Analysis for Office的workbook
  20. Linux系统之部署Samba服务

热门文章

  1. wget不是内部命令 windows_wget 不是内部或外部命令 - 卡饭网
  2. Markdown编辑器简单大概语法学习
  3. Zotero+坚果云的文献二三事
  4. 微信域名防封、域名检测接口api、域名跳转技术、360防拦截揭秘(一)------域名防封的核心技术
  5. Linux 引导过程与服务控制
  6. Hibernate中的一级缓存、二级缓存和懒加载
  7. dva是什么游戏_守望先锋:DVA这个皮肤小蛮腰不算什么,全部细节是这个小脚丫...
  8. 重要且紧急的事,紧急但不重要的事,重要但不紧急的事,既不紧急又不重要的事
  9. PyS2:RDD编程基础(二)
  10. Java微信如何自动添加好友,微信自动加好友 模拟位置