爬虫——python——百度地图经纬度查询——经纬度查看地点地名——利用百度API获取地名经纬度——爬取所有的中国地址

import requests
address = ‘40.8587960,86.866991‘
url = ‘http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&location=‘ + str(address)
response = requests.get(url)
answer = response.json()
print(‘得到反解数据‘, answer)

使用python爬虫

 1 import requests
 2 address = ‘40.8587960,86.866991‘
 3 url = ‘http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&location=‘ + str(address)
 4 response = requests.get(url)
 5 answer = response.json()
 6 print(‘得到反解数据‘, answer)
 7 lng = answer[‘result‘][‘location‘][‘lng‘]
 8 lat = answer[‘result‘][‘location‘][‘lat‘]
 9 formatted_address = answer[‘result‘][‘formatted_address‘]
10 business = answer[‘result‘][‘business‘]
11 city = answer[‘result‘][‘addressComponent‘][‘city‘]
12 direction = answer[‘result‘][‘addressComponent‘][‘city‘]
13 distance = answer[‘result‘][‘addressComponent‘][‘direction‘]
14 district = answer[‘result‘][‘addressComponent‘][‘district‘]
15 province = answer[‘result‘][‘addressComponent‘][‘province‘]
16 street = answer[‘result‘][‘addressComponent‘][‘street‘]
17 street_number = answer[‘result‘][‘addressComponent‘][‘street_number‘]
18 cityCode = answer[‘result‘][‘cityCode‘]
19 s = str(lng) + ‘|‘ + str(lat)+ ‘|‘  + str(formatted_address) + ‘|‘ + str(business) + ‘|‘+ str(city) + ‘|‘+ str(direction) + ‘|‘+ str(distance) + ‘|‘+ str(district) + ‘|‘+ str(province) + ‘|‘+ str(street) + ‘|‘+ str(street_number) + ‘|‘+ str(cityCode)
20 print(s)

解析数据

http://api.map.baidu.com/lbsapi/getpoint/index.html

 1 #鸡头1
 2 #129.000000,54.000000 #锚点(鸡头)
 3 #115.000000,54.0000000
 4 #115.000000,42.0000000  #北京
 5 #129.000000,42.000000 #沈阳
 6 #[‘54.0000000‘, ‘42.000000‘, ‘129.000000‘, ‘115.000000‘],#鸡头1
 7
 8 #鸡头2
 9 #129.000000,42.000000 #沈阳
10 #135.200000,42.000000
11 #129.000000,50.000000
12 #135.200000,50.000000
13    #[‘50.000000‘,‘42.000000‘,‘135.000000‘,‘129.000000‘],#鸡头2
14 #鸡头补充
15 #115.000000,42.0000000  #北京
16 #105.0000000,42.000000  #锚点(银川上面)
17 #105.0000000,45.500000 #乌兰巴托
18 #115.000000,45.500000
19 #[‘45.500000‘, ‘42.000000‘, ‘115.000000‘, ‘105.000000‘],#鸡头补充
20
21 #鸡屁股上补充
22 #105.0000000,42.000000  #锚点(银川上面)
23 #91.500000,45.500000  #乌鲁木齐
24 #105.0000000,45.500000  #乌兰巴托
25 #91.500000,42.000000 #锚点(鸡屁股)
26 #[‘45.500000‘, ‘42.000000‘, ‘105.0000000‘, ‘91.500000‘],#鸡屁股上补充
27 #鸡屁股上
28 #91.500000,42.000000 #锚点(鸡屁股)
29 #79.800000,42.000000 #啊拉木图
30 #79.800000,49.200000
31 #91.500000,49.200000
32 #[‘49.200000‘, ‘42.000000‘, ‘91.500000‘, ‘79.800000‘],#鸡屁股上
33 #鸡屁股下
34 #79.800000,42.000000 #啊拉木图
35 #79.800000,30.0000000 #巴雷利
36 #73.400000,42.000000
37 #73.400000,30.000000
38 #[‘42.000000‘, ‘30.000000‘, ‘79.800000‘, ‘73.400000‘],#鸡屁股下
39 #鸡下补充
40 #79.800000,30.0000000 #巴雷利
41 #97.300000,30.000000  #拉萨昌都(锚点)
42 #97.300000,26.800000
43 #79.800000,26.800000
44 #[‘42.000000‘, ‘30.000000‘, ‘97.300000‘, ‘79.800000‘],#鸡下补充
45 #鸡下
46 #97.300000,30.000000 #拉萨昌都(锚点)
47 #105.000000,30.000000 #(成都重庆贵阳)
48 #105.000000,21.000000 #河内
49 #97.300000,21.000000 #曼德勒
50 #[‘30.000000‘, ‘21.000000‘, ‘105.000000‘, ‘97.300000‘],#鸡下
51
52
53 #鸡胸
54 #105.0000000,42.000000  #锚点(银川上面)
55 #105.0000000,21.000000 #河内
56 #129.000000,42.000000 #沈阳
57 #129.000000,21.000000 #台北(海)
58 #[‘42.000000‘, ‘21.000000‘, ‘129.000000‘, ‘105.000000‘],#鸡胸
59
60 #鸡身
61 #105.000000,42.000000  #锚点(银川上面)
62 #79.800000,42.000000  #啊拉木图
63 #79.800000,30.000000 #巴雷利
64 #105.000000,30.000000  #(成都重庆贵阳)
65 #[‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],#鸡身
66 #鸡脚 (南海)
67 #105.000000,21.000000 #河内
68 #129.000000,21.000000 #台北(海)
69 #105.0000000,3.000000 #新加坡
70 #129.000000,3.000000 #海(苏拉威西海)
71 #[‘21.000000‘, ‘3.000000‘, ‘129.000000‘, ‘105.000000‘],

经纬度分析

 1 import requests
 2 from decimal import Decimal
 3 def obtain(address):
 4     url = ‘http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&location=‘ + str(address)
 5     response = requests.get(url)
 6     answer = response.json()
 7     print(‘得到反解数据‘, answer)
 8     lng = answer[‘result‘][‘location‘][‘lng‘]
 9     lat = answer[‘result‘][‘location‘][‘lat‘]
10     formatted_address = answer[‘result‘][‘formatted_address‘]
11     business = answer[‘result‘][‘business‘]
12     city = answer[‘result‘][‘addressComponent‘][‘city‘]
13     direction = answer[‘result‘][‘addressComponent‘][‘city‘]
14     distance = answer[‘result‘][‘addressComponent‘][‘direction‘]
15     district = answer[‘result‘][‘addressComponent‘][‘district‘]
16     province = answer[‘result‘][‘addressComponent‘][‘province‘]
17     street = answer[‘result‘][‘addressComponent‘][‘street‘]
18     street_number = answer[‘result‘][‘addressComponent‘][‘street_number‘]
19     cityCode = answer[‘result‘][‘cityCode‘]
20     s = str(‘%6f‘ % lng) + ‘|‘ + str(‘%6f‘ % lat) + ‘|‘ + str(formatted_address) + ‘|‘ + str(business) + ‘|‘ + str(
21         city) + ‘|‘ + str(direction) + ‘|‘ + str(distance) + ‘|‘ + str(district) + ‘|‘ + str(province) + ‘|‘ + str(
22         street) + ‘|‘ + str(street_number) + ‘|‘ + str(cityCode)
23     print(s)
24
25 def longitude(slon,precision,elon,slat):
26     while slon >= elon:
27         address = ‘%s,%s‘ % (slon,slat)  # 请求用的,经度,纬度,
28         obtain(address)#传入经度,纬度,获取地址地名
29         slon -= precision
30
31 #[‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
32 slon = Decimal(‘42.000000‘)#经度longitude开始
33 elon = Decimal(‘30.000000‘)#经度结束
34 slat=Decimal(‘105.000000‘)# 纬度latitude开始
35 elat=Decimal(‘79.800000‘)#纬度结束
36 precision = Decimal(‘5.0001000‘)#精度 0.0001000==1000米
37 while slat>=elat:
38     slat -= precision
39     longitude(slon,precision,elon,slat)

根据精度获取多个地名

 1 import requests
 2 from decimal import Decimal
 3 def obtain(address):
 4     url = ‘http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&location=‘ + str(address)
 5     response = requests.get(url)
 6     answer = response.json()
 7     print(‘得到反解数据‘, answer)
 8     lng = answer[‘result‘][‘location‘][‘lng‘]
 9     lat = answer[‘result‘][‘location‘][‘lat‘]
10     formatted_address = answer[‘result‘][‘formatted_address‘]
11     business = answer[‘result‘][‘business‘]
12     city = answer[‘result‘][‘addressComponent‘][‘city‘]
13     direction = answer[‘result‘][‘addressComponent‘][‘city‘]
14     distance = answer[‘result‘][‘addressComponent‘][‘direction‘]
15     district = answer[‘result‘][‘addressComponent‘][‘district‘]
16     province = answer[‘result‘][‘addressComponent‘][‘province‘]
17     street = answer[‘result‘][‘addressComponent‘][‘street‘]
18     street_number = answer[‘result‘][‘addressComponent‘][‘street_number‘]
19     cityCode = answer[‘result‘][‘cityCode‘]
20     s = str(‘%6f‘ % lng) + ‘|‘ + str(‘%6f‘ % lat) + ‘|‘ + str(formatted_address) + ‘|‘ + str(business) + ‘|‘ + str(
21         city) + ‘|‘ + str(direction) + ‘|‘ + str(distance) + ‘|‘ + str(district) + ‘|‘ + str(province) + ‘|‘ + str(
22         street) + ‘|‘ + str(street_number) + ‘|‘ + str(cityCode)
23     print(s)
24
25 def longitude(slon,precision,elon,slat):
26     while slon >= elon:
27         address = ‘%s,%s‘ % (slon,slat)  # 请求用的,经度,纬度,
28         obtain(address)#传入经度,纬度,获取地址地名
29         slon -= precision
30
31 LogLatList=[
32     [‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
33     [‘42.000000‘, ‘21.000000‘, ‘129.000000‘, ‘105.000000‘],  # 鸡胸
34     [‘50.000000‘, ‘42.000000‘, ‘135.000000‘,‘129.000000‘],  #鸡头2
35     [‘54.000000‘, ‘42.000000‘, ‘129.000000‘, ‘115.000000‘],  #鸡头1
36     [‘45.500000‘, ‘42.000000‘, ‘115.000000‘, ‘105.000000‘],  #鸡头补充
37     [‘49.200000‘, ‘42.000000‘, ‘91.500000‘, ‘79.800000‘],  # 鸡屁股上
38     [‘42.000000‘, ‘30.000000‘, ‘79.800000‘, ‘73.400000‘],  # 鸡屁股下
39     [‘45.500000‘, ‘42.000000‘, ‘105.000000‘, ‘91.500000‘],  #鸡屁股上补充
40     [‘30.000000‘, ‘21.000000‘, ‘105.000000‘, ‘97.300000‘],  # 鸡下
41     [‘42.000000‘, ‘30.000000‘, ‘97.300000‘, ‘79.800000‘],  #鸡下补充
42     [‘21.000000‘, ‘3.000000‘, ‘129.000000‘, ‘105.000000‘],  # 鸡脚 (南海)
43    ]
44 precision = Decimal(‘10.0001000‘)  # 精度 0.0001000==1000米
45 for single_list in LogLatList:
46     slons,elons,slats,elats=single_list
47     #[‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
48     slon = Decimal(slons)#经度longitude开始
49     elon = Decimal(elons)#经度结束
50     slat=Decimal(slats)# 纬度latitude开始
51     elat=Decimal(elats)#纬度结束
52
53     while slat>=elat:
54         slat -= precision
55         longitude(slon,precision,elon,slat)

批量获取数据

 1 import requests
 2 from decimal import Decimal
 3 import threading , time
 4 def obtain(address):
 5     url = ‘http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&location=‘ + str(address)
 6     response = requests.get(url)
 7     answer = response.json()
 8     print(‘得到反解数据‘, answer)
 9     lng = answer[‘result‘][‘location‘][‘lng‘]
10     lat = answer[‘result‘][‘location‘][‘lat‘]
11     formatted_address = answer[‘result‘][‘formatted_address‘]
12     business = answer[‘result‘][‘business‘]
13     city = answer[‘result‘][‘addressComponent‘][‘city‘]
14     direction = answer[‘result‘][‘addressComponent‘][‘city‘]
15     distance = answer[‘result‘][‘addressComponent‘][‘direction‘]
16     district = answer[‘result‘][‘addressComponent‘][‘district‘]
17     province = answer[‘result‘][‘addressComponent‘][‘province‘]
18     street = answer[‘result‘][‘addressComponent‘][‘street‘]
19     street_number = answer[‘result‘][‘addressComponent‘][‘street_number‘]
20     cityCode = answer[‘result‘][‘cityCode‘]
21     s = str(‘%6f‘ % lng) + ‘|‘ + str(‘%6f‘ % lat) + ‘|‘ + str(formatted_address) + ‘|‘ + str(business) + ‘|‘ + str(
22         city) + ‘|‘ + str(direction) + ‘|‘ + str(distance) + ‘|‘ + str(district) + ‘|‘ + str(province) + ‘|‘ + str(
23         street) + ‘|‘ + str(street_number) + ‘|‘ + str(cityCode)
24     print(s)
25
26 def longitude(slon,precision,elon,slat):
27     while slon >= elon:
28         address = ‘%s,%s‘ % (slon,slat)  # 请求用的,经度,纬度,
29         obtain(address)#传入经度,纬度,获取地址地名
30         slon -= precision
31
32
33 class Thre(threading.Thread):#继承线程中的类
34     #Thre(single_list,precision,ctime)
35     def __init__(self,single_list,precision,ctime):
36         super(Thre,self).__init__()#重新写父类,解决多继承问题
37         self.precision=precision#精度
38         self.single_list=single_list#单列表
39         self.ctime=ctime#当前时间
40     def run(self):
41         print(‘执行线程开始时间:‘, self.ctime, ‘执行的列表:‘,self.single_list)
42         slons, elons, slats, elats = self.single_list
43         # [‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
44         slon = Decimal(slons)  # 经度longitude开始
45         elon = Decimal(elons)  # 经度结束
46         slat = Decimal(slats)  # 纬度latitude开始
47         elat = Decimal(elats)  # 纬度结束
48         while slat >= elat:
49             slat -= self.precision
50             longitude(slon,self.precision, elon, slat)
51         else:
52             end_time=time.time()-self.ctime
53             print(‘执行线程所用时间:‘,end_time, ‘执行的列表:‘,self.single_list)
54
55 def main():
56     LogLatList=[
57         [‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
58         [‘42.000000‘, ‘21.000000‘, ‘129.000000‘, ‘105.000000‘],  # 鸡胸
59         [‘50.000000‘, ‘42.000000‘, ‘135.000000‘,‘129.000000‘],  #鸡头2
60         [‘54.000000‘, ‘42.000000‘, ‘129.000000‘, ‘115.000000‘],  #鸡头1
61         [‘45.500000‘, ‘42.000000‘, ‘115.000000‘, ‘105.000000‘],  #鸡头补充
62         [‘49.200000‘, ‘42.000000‘, ‘91.500000‘, ‘79.800000‘],  # 鸡屁股上
63         [‘42.000000‘, ‘30.000000‘, ‘79.800000‘, ‘73.400000‘],  # 鸡屁股下
64         [‘45.500000‘, ‘42.000000‘, ‘105.000000‘, ‘91.500000‘],  #鸡屁股上补充
65         [‘30.000000‘, ‘21.000000‘, ‘105.000000‘, ‘97.300000‘],  # 鸡下
66         [‘42.000000‘, ‘30.000000‘, ‘97.300000‘, ‘79.800000‘],  #鸡下补充
67         [‘21.000000‘, ‘3.000000‘, ‘129.000000‘, ‘105.000000‘],  # 鸡脚 (南海)
68        ]
69     precision = Decimal(‘20.0001000‘)  # 精度 0.0001000==1000米
70
71     thre_list=[] #线程列表
72     for single_list in LogLatList:
73         ctime=time.time()#当前时间
74         temp=Thre(single_list,precision,ctime)#实例化类
75         thre_list.append(temp)#线程列表
76     for thre in thre_list:#线程列表
77         thre.start()#执行单个线程
78
79 if __name__ == ‘__main__‘:
80     main()

多线程获取数据

 1 import requests
 2 from decimal import Decimal
 3 import threading , time
 4 def obtain(address,file_name):
 5     url = ‘http://api.map.baidu.com/geocoder?output=json&key=f247cdb592eb43ebac6ccd27f796e2d2&location=‘ + str(address)
 6     response = requests.get(url)
 7     answer = response.json()
 8     print(‘得到反解数据‘, answer)
 9     lng = answer[‘result‘][‘location‘][‘lng‘]
10     lat = answer[‘result‘][‘location‘][‘lat‘]
11     formatted_address = answer[‘result‘][‘formatted_address‘]
12     business = answer[‘result‘][‘business‘]
13     city = answer[‘result‘][‘addressComponent‘][‘city‘]
14     direction = answer[‘result‘][‘addressComponent‘][‘city‘]
15     distance = answer[‘result‘][‘addressComponent‘][‘direction‘]
16     district = answer[‘result‘][‘addressComponent‘][‘district‘]
17     province = answer[‘result‘][‘addressComponent‘][‘province‘]
18     street = answer[‘result‘][‘addressComponent‘][‘street‘]
19     street_number = answer[‘result‘][‘addressComponent‘][‘street_number‘]
20     cityCode = answer[‘result‘][‘cityCode‘]
21     s = str(‘%6f‘ % lng) + ‘|‘ + str(‘%6f‘ % lat) + ‘|‘ + str(formatted_address) + ‘|‘ + str(business) + ‘|‘ + str(
22         city) + ‘|‘ + str(direction) + ‘|‘ + str(distance) + ‘|‘ + str(district) + ‘|‘ + str(province) + ‘|‘ + str(
23         street) + ‘|‘ + str(street_number) + ‘|‘ + str(cityCode)
24     print(s)
25     if cityCode==0:
26         #print(‘外国‘)
27         pass
28     else:
29         #print(s)
30         fname=str(file_name)+‘list‘
31         with open(fname, ‘a+‘, encoding=(‘utf-8‘)) as f:
32             f.write(s+‘\n‘)
33
34 def longitude(slon,precision,elon,slat,file_name):
35     while slon >= elon:
36         address = ‘%s,%s‘ % (slon,slat)  # 请求用的,经度,纬度,
37         obtain(address,file_name)#传入经度,纬度,获取地址地名
38         slon -= precision
39
40
41 class Thre(threading.Thread):#继承线程中的类
42     #Thre(single_list,precision,ctime)
43     #temp = Thre(single_list, precision, ctime, file_name)  # 实例化类
44     def __init__(self,single_list,precision,ctime,file_name):
45         super(Thre,self).__init__()#重新写父类,解决多继承问题
46         self.precision=precision#精度
47         self.single_list=single_list#单列表
48         self.ctime=ctime#当前时间
49         self.file_name=file_name#文件名
50     def run(self):
51         print(‘执行线程开始时间:‘, self.ctime, ‘执行的列表:‘,self.single_list)
52         slons, elons, slats, elats = self.single_list
53         # [‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
54         slon = Decimal(slons)  # 经度longitude开始
55         elon = Decimal(elons)  # 经度结束
56         slat = Decimal(slats)  # 纬度latitude开始
57         elat = Decimal(elats)  # 纬度结束
58         while slat >= elat:
59             slat -= self.precision
60             longitude(slon,self.precision, elon, slat,self.file_name)
61         else:
62             end_time=time.time()-self.ctime
63             print(‘执行线程所用时间:‘,end_time, ‘执行的列表:‘,self.single_list)
64
65 def main():
66     LogLatList=[
67         [‘42.000000‘, ‘30.000000‘, ‘105.000000‘, ‘79.800000‘],  # 鸡身
68         [‘42.000000‘, ‘21.000000‘, ‘129.000000‘, ‘105.000000‘],  # 鸡胸
69         [‘50.000000‘, ‘42.000000‘, ‘135.000000‘,‘129.000000‘],  #鸡头2
70         [‘54.000000‘, ‘42.000000‘, ‘129.000000‘, ‘115.000000‘],  #鸡头1
71         [‘45.500000‘, ‘42.000000‘, ‘115.000000‘, ‘105.000000‘],  #鸡头补充
72         [‘49.200000‘, ‘42.000000‘, ‘91.500000‘, ‘79.800000‘],  # 鸡屁股上
73         [‘42.000000‘, ‘30.000000‘, ‘79.800000‘, ‘73.400000‘],  # 鸡屁股下
74         [‘45.500000‘, ‘42.000000‘, ‘105.000000‘, ‘91.500000‘],  #鸡屁股上补充
75         [‘30.000000‘, ‘21.000000‘, ‘105.000000‘, ‘97.300000‘],  # 鸡下
76         [‘42.000000‘, ‘30.000000‘, ‘97.300000‘, ‘79.800000‘],  #鸡下补充
77         [‘21.000000‘, ‘3.000000‘, ‘129.000000‘, ‘105.000000‘],  # 鸡脚 (南海)
78        ]
79     # ——测试使用——开始————
80     precision = Decimal(‘1.0001000‘)  # 精度 0.0001000==1000米
81     # ——测试使用——结束————
82
83     #——实际获取时替换——精度自己控制————建议是 0.0001000 ————开始————
84     #precision = Decimal(‘0.0001000‘)  # 精度 0.0001000==1000米
85     # ——实际获取时替换——精度自己控制————建议是 0.0001000 ————结束————
86
87     file_name=0
88
89     thre_list=[] #线程列表
90     for single_list in LogLatList:
91         ctime=time.time()#当前时间
92         temp=Thre(single_list,precision,ctime,file_name)#实例化类
93         file_name+=1
94         thre_list.append(temp)#线程列表
95     for thre in thre_list:#线程列表
96         thre.start()#执行单个线程
97
98 if __name__ == ‘__main__‘:
99     main()

写入到文件

原文地址:https://www.cnblogs.com/ujq3/p/9775376.html

时间: 2024-10-25 13:08:49

爬虫——python——百度地图经纬度查询——经纬度查看地点地名——利用百度API获取地名经纬度——爬取所有的中国地址的相关文章

Android百度地图开发-第一篇:申请、搭建百度地图

一.前言 这是第一篇关于Android使用百度地图的学习记录,主要记录: 1.在百度地图开发者平台上申请API Key. 2.在自己的应用中加入百度地图的Android版SDK. 3.在自己的应用中显示一个地图. 二.在百度地图开发者平台上申请API Key 百度地图开发者平台地址:http://lbsyun.baidu.com/index.php?title=%E9%A6%96%E9%A1%B5.点击界面的"申请密钥",进入界面之后,点击"创建应用"按钮. 将应用

百度地图动态显示查询结构

<script type="text/javascript"> // 百度地图API功能 function G(id) { return document.getElementById(id); } var map = new BMap.Map("l-map"); map.centerAndZoom("北京",12); // 初始化地图,设置城市和地图级别. var ac = new BMap.Autocomplete( //建立一个

百度地图距离计算,计算结果和调用百度的api一样

 var DEF_PI =Math.PI;// 3.14159265359 var DEF_2PI =2 *Math.PI;// 6.28318530712 var DEF_PI180 =Math.PI/ 180.0;// 0.01745329252 var DEF_R =6370996.81;// radius of earth // 利用弧夹角方式计算地图上两点之间的距离,和百度地图计算结果不一致 function GetShortDistance(lon1, lat1, lon2, l

百度地图开发-将多个地点标记在地图上,点击节点弹出PopupWindow

最近在写一个安卓程序,用到了百度地图API的一些内容,就随便玩耍了一下. 这个DEMO是用来将多个地点标记在地图上,然后点击节点弹出PopupWindow 下面是一些截图: main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout

针对源代码和检查元素不一致的网页爬虫——利用Selenium、PhantomJS、bs4爬取12306的列车途径站信息

整个程序的核心难点在于上次豆瓣爬虫针对的是静态网页,源代码和检查元素内容相同:而在12306的查找搜索过程中,其网页发生变化(出现了查找到的数据),这个过程是动态的,使得我们在审查元素中能一一对应看到的表格数据没有显示在源代码中.这也是这次12306爬虫和上次豆瓣书单爬虫的最大不同点. 查找相关资料,我选择使用Selenium的PhantomJS模拟浏览器爬取源代码,这样获取到的datas包含了我需要的(查找搜索出的)途径站数据. 暂时把整个程序分为了这几个部分:(1)提取列车Code和No信息

百度地图 公交查询功能

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script&g

python获取网页精准爬取数据

import reimport urllib.requeststring='<div class="name">(.*?)</div>'huo=urllib.request.urlopen("https://read.douban.com/provider/all").read()huo=huo.decode("utf-8")huo1=re.compile(string).findall(str(huo))hom=open

零基础掌握百度地图兴趣点获取POI爬虫(python语言爬取)(基础篇)

实现目的:爬取昆明市范围内的全部中学数据,包括名称.坐标. 先进入基础篇,本篇主要讲原理方面,并实现步骤分解,为python代码编写打基础. 因为是0基础开始,所以讲得会比较详细. 如实现目的所讲,爬取昆明市全部中学数据,就是获取百度地图上昆明市范围内所有关键字带中学的地理信息数据(兴趣点). 怎么把百度地图上的数据抓取下来呢? 以下是教程: 本篇目录如下: 1. 百度地图开放平台注册,AK获取 2.关于ak的说明 3.请求URL说明 4.百度地图坐标拾取器 5.以坐标范围获取兴趣点POI 6.

百度地图地点搜索和鼠标点击地点获取经纬度

百度地图地点搜索和鼠标点击地点获取经纬度,这些都是地图比较基本 效果图:如下 代码部分: <!DOCTYPE html><html>    <head>    <meta charset="utf-8">    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />