#!/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,macurl2pathuser_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 = [headers]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 ' A ' in i: address=re.findall (R "latitude= (. *?) &limit=24&longitude= (. *?) &offset= ", url) print ("Shop name: {}, Rank {}, locating address coordinates: latitude {} longitude {}. ". Format (i,num,address[0][0],address[0][1)) flag=False breakif __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)
Execution Result:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/85/54/wKiom1egNEqB6UCCAAGK9YtLnyc277.png-wh_500x0-wm_3 -wmp_4-s_346541771.png "title=" qq picture 20160802134824.png "alt=" Wkiom1egneqb6uccaagk9ytlnyc277.png-wh_50 "/>
Crawling hungry with a Python crawler. List of takeout shops