使用Python和BS4在县级别上刮取地址

问题描述 投票:0回答:1

好吧,所以我正在尝试为英国各地的橄榄球队和球员创建一个“夹具查找器”网站,我目前正在尝试使用python和Beautifulsoup实施网络刮刀,以便刮取谷歌的地址,然后进行地理编码和作为map API的long&lat插入到数据库中,以便为用户映射它。

我的问题是,有没有办法我可以简单地使用谷歌地理编码器API来检索该特定县的所有俱乐部的长和拉,然后通过BeautifulSoup解析以检索生成的页面的长和拉特(和然后在以下示例中冲洗并重复英国的所有县):https://pypi.python.org/pypi/geocoder/1.8.0#downloads,但在县级别

或者,如果有人可能会从谷歌地图中删除可能的信息,因为我普遍认为不允许删除地图。

任何见解将不胜感激

python json google-maps beautifulsoup geocoding
1个回答
2
投票

使用Python Client for Google Maps Services和这段代码我得到了查询'Rugby Club, London'的名称和位置(以及更多)

你将不得不在developers.google.com/console上创建自己的项目,激活Places API for Web ServiceDesktop Application没有版本)并获得PlacesAPI的证书 - 它给你自己的key=(API密钥)。

当前的key=处于活动状态,因此您可以测试代码,但我稍后会将其停用。

import googlemaps

gmaps = googlemaps.Client(key='AIzaSyBiC8vKEEF-MLP9a2de0PLs-S_XrEL0kSQ')

results = gmaps.places('Rugby Club, London')

for key in item.keys():
    print('key:', key)

print('-----')

for item in results['results']:
    print('name:', item['name'])
    print('lat:', item['geometry']['location']['lat'])
    print('lng:', item['geometry']['location']['lng'])
    print('location:', item['geometry']['location'])
    print('---')

print('-----')

#for item in results['results'][:1]:
#    for key, value in item.items():
#        print(key, ':', value)

结果:(可用密钥和一些名称和位置)

key: formatted_address
key: geometry
key: icon
key: id
key: name
key: opening_hours
key: photos
key: place_id
key: rating
key: reference
key: types
-----
name: East London Rugby Football Club
lat: 51.5291765
lng: 0.0102242
location: {'lat': 51.5291765, 'lng': 0.0102242}
---
name: Hampstead Rugby Football Club
lat: 51.5571358
lng: -0.1555037
location: {'lat': 51.5571358, 'lng': -0.1555037}
---
name: Chiswick Rugby Club
lat: 51.47323
lng: -0.256633
location: {'lat': 51.47323, 'lng': -0.256633}
---
name: Wimbledon Rugby Football Club
lat: 51.41975009999999
lng: -0.2464434
location: {'lat': 51.41975009999999, 'lng': -0.2464434}
---
name: Saracens Amateur RFC
lat: 51.64230209999999
lng: -0.1429848
location: {'lat': 51.64230209999999, 'lng': -0.1429848}
---
name: Kilburn Cosmos RFC
lat: 51.55542000000001
lng: -0.2297043000000001
location: {'lat': 51.55542000000001, 'lng': -0.2297043000000001}
---
name: Barnes Rugby Football Club
lat: 51.47568860000001
lng: -0.2373847
location: {'lat': 51.47568860000001, 'lng': -0.2373847}
---
name: Southwark Tigers Rugby Club
lat: 51.4839377
lng: -0.07720149999999999
location: {'lat': 51.4839377, 'lng': -0.07720149999999999}
---
name: HACKNEY RFC
lat: 51.5732467
lng: -0.0611062
location: {'lat': 51.5732467, 'lng': -0.0611062}
---
name: UCS Old Boys Rugby Club
lat: 51.5575127
lng: -0.2022654
location: {'lat': 51.5575127, 'lng': -0.2022654}
---
name: Millwall Rugby Club
lat: 51.487884
lng: -0.010493
location: {'lat': 51.487884, 'lng': -0.010493}
---
name: Haringey Rhinos RFC
lat: 51.604738
lng: -0.099553
location: {'lat': 51.604738, 'lng': -0.099553}
---
name: Finchley RFC
lat: 51.6067705
lng: -0.1698911
location: {'lat': 51.6067705, 'lng': -0.1698911}
---
name: Trailfinders Rugby Club
lat: 51.520878
lng: -0.306115
location: {'lat': 51.520878, 'lng': -0.306115}
---
name: Old Ruts Rugby Club
lat: 51.4079431
lng: -0.1993505
location: {'lat': 51.4079431, 'lng': -0.1993505}
---
name: Ealing Trailfinders Rugby Club
lat: 51.524832
lng: -0.3293849999999999
location: {'lat': 51.524832, 'lng': -0.3293849999999999}
---
name: Chingford Rugby Football Club
lat: 51.6301123
lng: -0.0171661
location: {'lat': 51.6301123, 'lng': -0.0171661}
---
name: Old Elthamians RFC Senior Rugby
lat: 51.43445149999999
lng: 0.0296538
location: {'lat': 51.43445149999999, 'lng': 0.0296538}
---
name: Eton Manor RFC
lat: 51.579528
lng: 0.03874
location: {'lat': 51.579528, 'lng': 0.03874}
---
name: London Skolars Rugby League Club
lat: 51.60465900000001
lng: -0.100032
location: {'lat': 51.60465900000001, 'lng': -0.100032}
---
© www.soinside.com 2019 - 2024. All rights reserved.