Home > OS >  Web Scrape interactive map coordinates
Web Scrape interactive map coordinates

Time:01-18

I am struggling with how to scrape an interactive map or coordinates from the website,

below is an example of the map (or coordinates) I would like to scrape with requests / bs4.

The idea is to scrape like 100 or so map locations and plot them a map graph.

Could you please advise on how to scrape the map bottom of the website:

https://www.njuskalo.hr/nekretnine/gradevinsko-zemljiste-zagreb-lucko-5000-m2-oglas-34732559

CodePudding user response:

The location data is hidden in a script tag within the HTML, you can get it out like this:

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'])
  •  Tags:  
  • Related