python--using the high-de API to get POI (take Shenzhen Nanshan Healthcare service POI for example)

Source: Internet
Author: User

The following content is original, reproduced please indicate the source.

1 ImportXlwt#create Excel, see Code line 8,9,11,25,28;cmd: Run pip install XLWT to install2 ImportUrllib.request#URL request, Python3, the difference between Python2 and 3 urllib see: http://blog.csdn.net/Jurbo/article/details/523136363  fromBs4ImportBeautifulSoup#quick access to the Web page tag content Library; CMD: run pip install beautifulsoup4 to install4 ImportRe#Library with regular expressions, code line 7, quick learn see: http://www.runoob.com/regexp/regexp-syntax.html5Poitag = ["ID","name","type","TypeCode","Biz_type","Address"," Location","Tel","pname","CityName","Adname"]#when the return result is controlled to base, the POI label category of the output6Poisouptag = ["Idsoup","Namesoup","Typesoup","Typecodesoup","Biz_typesoup","Addresssoup","Locationsoup","Telsoup","Pnamesoup","Citynamesoup","Adnamesoup"]#packaging corresponding to the soup7Pattern = Re.compile ("(?:>) (. *?) (?=<)", Re. S#Organization Regular Expression8Poiexcel =XLWT. Workbook ()#New Workbook9Sheet = Poiexcel.add_sheet ("Poiresult")#Create a new "Poiresult" worksheetTen  forColindexinchRange (len (poitag)): OneSheet.write (0,colindex,poitag[colindex])#writing a table header Aoffset = 10#Instance settings show 10 poi per page (official limit 25) -MaxPage = 10#set the maximum number of pages to 10 pages (officially 100 pages) -Types ="090000" #sample category for healthcare services poi, download: Http://a.amap.com/lbs/static/zip/AMap_poicode.zip theCity ="440305" #The example category is Shenzhen, South Mountain, download: Http://a.amap.com/lbs/static/zip/AMap_adcode_citycode.zip -  forPageIndexinchRange (1, MaxPage + 1): -     Try:   -URL ="http://restapi.amap.com/v3/place/text?&keywords=&types="+ Types +"&city="+ City +"&citylimit=true&output=xml&offset="+ str (offset) +"&page="+ STR (PAGEINDEX) +"&key= your key&extensions=base." +         #the requested structured URL address is as above; Please use your own key, see: http://lbs.amap.com/api/webservice/guide/api/search/ -Poisoup = BeautifulSoup (Urllib.request.urlopen (URL). Read (),"XML")#read the page that corresponds to the page number +          forTagindexinchRange (len (poitag)): APoisouptag[tagindex] = Poisoup.findall (Poitag[tagindex])#read the POI label content of the corresponding page number according to tag at          forRowIndexinchRange (len (poisouptag[0)): -              forColindexinchRange (len (poisouptag)): -Sheet.write (Len (poisouptag[0]) * (pageIndex-1) + RowIndex + 1, Colindex, Re.findall (Pattern,str (Poisouptag[colindex][rowindex ))) -                 #extracts content from a regular expression and writes to the corresponding row and column -     exceptException as E: -         Print(e)#Set Error Output inPoiexcel.save ("e:/poi&"+ Types +"&"+ City +". xls")#Save - Print("done!")#End

Note: When the page is too large, some cells have the probability of rewriting errors (guessing and the original page of the page data is incomplete), because set an error, does not affect the operation. But it can cause a very small percentage of poi loss.

python--using the high-de API to get POI (take Shenzhen Nanshan Healthcare service POI for example)

Related Article

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.