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)