代码拉取完成,页面将自动刷新
__author__ = 'vivienfanghua'
import urllib2
from bs4 import BeautifulSoup
import codecs
import json
baseurl="http://api.map.baidu.com/place/v2/search?q=%E5%8C%BB%E7%96%97®ion=%E6%AD%A6%E6%B1%89%E5%B8%82&page_size=20&page_num=pppnum&output=json&ak=ZWl4eD5D2leA0RxRw7c6hRwR"
output=codecs.open("D:/output.txt","w","utf8")
for i in range(20):
url=baseurl.replace("pppnum",str(i))
request = urllib2.Request(url)
response = urllib2.urlopen(request)
content=response.read().decode("utf-8")
js=json.loads(content)
for j in js["results"]:
name=j["name"]
telephone=""
if j.has_key("telephone"):
telephone=j["telephone"]
lat=j["location"]["lat"]
lng=j["location"]["lng"]
address=j["address"]
output.write(name+u" "+unicode(lat)+u" "+unicode(lng)+u" "+address+u" "+telephone+u"\n")
print("Done")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。