Crawling hungry with a Python crawler. List of takeout shops

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.