I have a website that displays a map using mapbox.
I want to scrape the points. The geolocation is not easiyliy accessable via the network tab. what do i do?
Assistant
When Mapbox data isn't easily visible in the network tab, here are several approaches to extract the points:
1. Check Network Tab More Thoroughly
Look for requests to .pbf files (Mapbox Vector Tiles)
Search for requests containing "geojson", "features", or "tiles"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Look for requests that happen on map movement/zoom
2. Inspect JavaScript Sources
The data might be embedded directly in the page:
javascript
// In browser console, try:
window.mapboxgl
window.map
// Look for map instances and their data sources
3. Access Mapbox GL JS Methods
If you can access the map instance in the console:
javascript
// Find the map instance (often window.map or similar)
map.getStyle().sources // Shows all data sources
map.queryRenderedFeatures() // Gets visible features
map.querySourceFeatures('source-id') // Gets all features from a source
4. Browser Automation Approach
Use tools like Puppeteer or Playwright to:
Intercept responses programmatically
Execute JavaScript to extract data from the map instance
Capture WebGL/Canvas data if needed
5. Check Page Source
Sometimes data is embedded as:
Inline JavaScript variables
JSON-LD structured data
Hidden DOM elements
Would you like me to elaborate on any of these methods, or help you identify which approach would work best for your specific website?
User
mapboxgl is available on the site and i can also catch the pbf
Assistant
Great! Since you have access to both mapboxgl and the .pbf files, you have two solid options:
Option 1: Extract via Mapbox GL JS (Easier)
In the browser console:
javascript
// Get all loaded sources
const sources = map.getStyle().sources;
console.log(sources);
// Extract all features from visible area
const features = map.queryRenderedFeatures();
console.log(features);
// Extract features from a specific source/layer
const layerFeatures = map.queryRenderedFeatures({
layers: ['your-layer-name']
});
// Get all features from a source (not just visible ones)
const sourceFeatures = map.querySourceFeatures('source-name');
// Convert to GeoJSON for easy export
const geojson = {
type: 'FeatureCollection',
features: features
};
// Download as file
const dataStr = JSON.stringify(geojson);
const dataBlob = new Blob([dataStr], {type: 'application/json'});
const url = URL.createObjectURL(dataBlob);
const link = document.createElement('a');
link.href = url;
link.download = 'map-data.geojson';
link.click();
Option 2: Decode PBF Files (More Complete)
If you need all data (not just visible), decode the .pbf files:
javascript
// Using Node.js with pbf and vt-pbf packages
const Pbf = require('pbf');
const VectorTile = require('@mapbox/vector-tile').VectorTile;
const fs = require('fs');
const buffer = fs.readFileSync('your-tile.pbf');
const tile = new VectorTile(new Pbf(buffer));
// Extract features from layers
for (const layerName in tile.layers) {
const layer = tile.layers[layerName];
for (let i = 0; i < layer.length; i++) {
const feature = layer.feature(i);
console.log(feature.toGeoJSON(x, y, z)); // x,y,z are tile coordinates
}
}
Which approach would you prefer? The browser method is quicker for visible data, while PBF decoding gets you everything.