簡體   English   中英

帶Python和BS4的縣級地址爬網

[英]Scraping addresses on a county Scale w/ Python & BS4

好的,因此,我正在嘗試為英國的橄欖球隊和球員創建一個“夾具查找器”網站,我目前正在嘗試使用python和Beautifulsoup實施網絡抓取工具,以抓取Google的地址,然后進行地址解析和作為地圖API的long&lat插入數據庫中,以便為用戶映射出來。

我的問題是,有沒有一種方法可以讓我簡單地使用google geocoder API來檢索該特定縣中所有俱樂部的經度和緯度,然后解析BeautifulSoup以從生成的頁面中檢索經度和緯度(並且然后只需按照以下示例進行沖洗,然后對英國的所有縣重復一次): https//pypi.python.org/pypi/geocoder/1.8.0#downloads但在縣級范圍內

或者,如果有人可以發現可能會從Google地圖上刪除列表的信息,因為我普遍認為不允許刪除地圖。

任何見解將不勝感激

使用適用於Google Maps Services的Python客戶端和此代碼,我獲得了查詢'Rugby Club, London'名稱和位置(以及更多)

您將必須在developers.google.com/console上創建自己的項目,激活Places API for Web Service (沒有適用於Desktop Application版本),並獲得PlacesAPI的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}
---

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM