Public
Edited
Nov 22, 2023
Insert cell
# Atlas Obscura scraping
Insert cell
user = Inputs.text({value:'kevbot'})
Insert cell
user_places = {
var regex = /AtlasObscura\.user_profile\s*=\s*({[\s\S]*?\}\}\]\}\});/;

// Find the match
var match = text.match(regex);

// Initialize obj as null
var obj = null;

// Check if there was a match and parse the JSON
if (match && match[1]) {
try {
// The JSON object string is in match[1]
obj = JSON.parse(match[1]);
} catch (e) {
console.error("Parsing error:", e);
}
}
return obj.user.places
}
Insert cell
url = `https://www.atlasobscura.com/users/${user.value}?view=passport`
Insert cell
fetch(url) // rip, CORS cross origin resource sharing (avoids cross-site scripting attacks)
Insert cell
import {fetchp} from '@tomlarkworthy/fetchp' // NOTE notebook must be published/link-shared for this to run
Insert cell
fetchp
Insert cell
response = fetchp(url)
Insert cell
response.status
Insert cell
text = response.text() // empty?
Insert cell
baz = 42
Insert cell
html`${text}`
Insert cell
places = ['australia', 'japan', 'germany']
Insert cell
(await fetchp(`https://www.atlasobscura.com/things-to-do/australia`)).status
Insert cell
result = Promise.all(places.map(async p => ((await fetchp(`https://www.atlasobscura.com/things-to-do/${p}`)).text())))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more