ktyu65 发表于 2016-8-3 09:11:30

用python爬虫爬取饿了么外卖店铺排名



#!/usr/bin/env python
# encoding: utf-8

"""
@version: ??
@author: phpergao
@license: Apache Licence
@file: elm_paiming.py
@time: 2016/8/2 11:18
"""

import requests,re,urllib,codeop,urllib.request,nturl2path,macurl2path
User_Agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"#伪装成浏览器访问
headers = ('User-Agent', User_Agent)
opener = urllib.request.build_opener()
opener.addheaders =
def paiming(latitude,longitude):
    a=0
    flag=True
    num=0
    while flag:
      url ="https://www.ele.me/restapi/shopping/restaurants?extras%5B%5D=activities&geohash=ws0edemxcy4&latitude={}&limit=24&longitude={}&offset={}".format(latitude,longitude,a)
      a+=24
      ret = opener.open(url).read()

      html = re.findall(r'''"latitude".*?"longitude":.*?,"name":"(.*?)","next_business_time":".*?","only_use_poi":.*?,"opening_hours":''', str(ret,'utf8'))
      for i in html:
            num += 1
            #print(i)
            if '72' in i:
                address=re.findall(r"latitude=(.*?)&limit=24&longitude=(.*?)&offset=",url)
                print("店铺名:{},排名{},定位地址坐标:纬度{}经度{}.".format(i,num,address,address))
                flag=False

                break


if __name__ == '__main__':
    urlslist=["23.13445,113.32062",
            "23.12102,113.28648",
            "23.10144,113.32775"
    ]
    for i in urlslist:
      latitude, longitude=i.split(',')
      paiming(latitude,longitude)


执行结果:


页: [1]
查看完整版本: 用python爬虫爬取饿了么外卖店铺排名