This site fetch the data from this API https://maps.pandora.net/api/getAsyncLocations
with search
value in query parameters. The result is a JSON object with a field maplist
which contains html data (a single div). This div embed several JSON objects comma delimited :
curl 'https://maps.pandora.net/api/getAsyncLocations?level=domain&template=domain&search=Melbourne+Victoria%2C+Australie'
So we need to rearrange the JSON objects comma delimited into an array to parse it. The following example uses curl, jq (json parser), sed & pup (html parser) to extract the data :
search="Melbourne+Victoria+Australie"
curl -s -G 'https://maps.pandora.net/api/getAsyncLocations' \
-d 'level=domain' \
-d 'template=domain' \
-d "search=$search" | \
jq -r '.maplist' | \
pup -p div text{} | \
sed '$ s/.$//' | \
sed -e "\$a]" | \
sed '1s/^/[/' | \
jq '.[] | {
location: .location_name,
address: .address_1,
complement: (.city + "," + .big_region + " " + .location_post_code)
}'
In python with python-requests & beautifulsoup :
import requests
from bs4 import BeautifulSoup
import json
search = "Melbourne+Victoria+Australie"
response = requests.get(
'https://maps.pandora.net/api/getAsyncLocations',
params = {
'level':'domain',
'template':'domain',
'search': search
}
)
soup = BeautifulSoup(response.json()['maplist'], 'html.parser')
formatted_json = "[{}]".format(soup.div.string[:-1])
data = json.loads(formatted_json)
print([
(i['location_name'], i['address_1'], i['city'], i['big_region'], i['location_post_code'])
for i in data
])