我正在努力解決如何從網站上抓取互動式地圖或坐標,
下面是我想用 requests / bs4 抓取的地圖(或坐標)示例。
這個想法是抓取大約 100 個地圖位置并將它們繪制成地圖圖。
您能否建議如何刮取網站底部的地圖:
https://www.njuskalo.hr/nekretnine/gradevinsko-zemljiste-zagreb-lucko-5000-m2-oglas-34732559
uj5u.com熱心網友回復:
位置資料隱藏在 HTML 中的腳本標記中,您可以像這樣將其取出:
import requests
import json
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'}
url = 'https://www.njuskalo.hr/nekretnine/gradevinsko-zemljiste-zagreb-lucko-5000-m2-oglas-34732559'
resp = requests.get(url,headers=headers)
start = '"defaultMarker":'
end = ',"cluster":{"icon1'
s = resp.text
dirty_json = s[s.find(start) len(start):s.rfind(end)].strip() #get the json out the html
clean_json = json.loads(dirty_json)
print(clean_json['lat'],clean_json['lng'])
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/415152.html
標籤:
