用Python抓取高德上的信息程序没有错误但是没有抓取到信息?????

Cherryine 2017-10-30 08:00:04
import urllib.request
import urllib.parse
import _json
import os

cityList = [
["0431","长春"],
["0432","吉林"],
["1433","延边"],
["0436","白城"],
["0439","白山"],
["0437","辽源"],
["0434","四平"],
["0438","松原"],
["0435","通化"],
]

def url_open(url):
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36')
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8','ignore')
return html

def get_urlList():
key = "f75fc0bb06d60892356b45bc972e375a"
engHP = urllib.parse.quote("医院")
urlList = []
for city in cityList:
url = "http://restapi.amap.com/v3/place/text?key="+key+"&keywords="+engHP+"&types="+engHP+"&city="+city[0]+"&children=1&extensions=all"
urlList.append(url)
return urlList

def total_Hospital():
urlList = get_urlList()
i = 0
totalNumber = 0
cityListNo = []
for url in urlList:
html = url_open(url)
target = _json.loads(html)
HPNo = int(target['count'])
pageNo = divmod(HPNo,20)[0]+1 if divmod(HPNo,20)[1]>0 else divmod(HPNo,20)[0]
cityListNo.append([cityList[i][0],cityList[i][1],HPNo,pageNo])
totalNumber = totalNumber + HPNo
i = i + 1
return cityListNo

def get_HPByCity():
cityListNo = total_Hospital()
key = "f75fc0bb06d60892356b45bc972e375a"
engHP = urllib.parse.quote("医院")
cityUrlList = []
for city in cityListNo:
urlList = []
for i in range(city[3]):
url = "http://restapi.amap.com/v3/place/text?key="+key+"&keywords="+engHP+"&types="+engHP+"&city="+city[0]+"&children=1&offset=20&page="+str(i+1)+"&extensions=all"
urlList.append(url)
cityUrlList.append(urlList)
return cityUrlList

def get_HPList():
cityUrlList = get_HPByCity()
allList = []
for cityUrl in cityUrlList:
cityPoisList = []
for url in cityUrl:
html = url_open(url)
target = _json.loads(html)
pagePoiList = target['pois']
cityPoisList.append(pagePoiList)
cityPoisList = sum(cityPoisList,[])
allList.append(cityPoisList)
allList = sum(allList,[])
ffff = []
i = 0
for aList in allList:
try:
print(aList['id'])
dddd = aList['id']+'\t'+aList['name']+'\t'+aList['pname']+'\t'+aList['cityname']+'\t'+aList['adname']+'\t'+aList['address']+'\t'+aList['type']+'\t'+aList['location']+'\n'
i = i + 1
except Exception as e:
continue
else:
ffff.append(dddd)



os.getcwd()
file_name = 'JLHospital.xls'
f = open(file_name,'w')
f.writelines(ffff)
f.close()


if __name__ == '__main__':
get_HPList()








代码是照着老师给的例子写的,程序能运行而且没有错误但是没有抓到任何数据,请求各位大佬帮我解决解决,我在这跪谢各位大佬了!!!!!!!
...全文
288 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧