Using Browser DevTools to Find APIs
A practical guide to using Chrome DevTools Network tab to discover API endpoints, inspect requests, and export them for use in Python.
Chrome DevTools is your best friend for discovering the API calls a website makes behind the scenes. Every piece of dynamic content on a page, search results, product listings, user profiles, is typically fetched from an API endpoint.
Opening DevTools
- Press F12 (or Cmd+Option+I on Mac) to open DevTools
- Click the Network tab
- Check Preserve log to keep requests across page navigations
- Select the Fetch/XHR filter to show only API calls
Step-by-Step: Finding an API
Interact with the site while watching the Network tab. For example, searching on a site:
- Type a search query and press Enter
- Look for new XHR requests in the Network panel
- Click on a request to inspect it
- Check the Preview tab, if it shows JSON, you found an API
- Switch to the Headers tab to see the full URL, method, and headers
Copying a Request to Python
Right-click any request in DevTools and choose Copy > Copy as cURL (bash). Then convert it:
# Converted from a cURL export
import requests
url = "https://www.example.com/api/search"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Accept": "application/json",
"Cookie": "session_id=abc123; preferences=lang_en",
}
params = {"q": "web scraping", "page": 1}
response = requests.get(url, headers=headers, params=params, timeout=15)
data = response.json()
for result in data.get("items", []):
print(result["title"])
You can also use the curlconverter package to automate the conversion:
pip install curlconverter
import curlconverter
curl_command = 'curl "https://api.example.com/data" -H "Authorization: Bearer token"'
python_code = curlconverter.to_python(curl_command)
print(python_code)
Useful DevTools Features
| Feature | How to Access | Use Case |
|---|---|---|
| Filter by URL | Type in the filter box | Find specific endpoints |
| Replay request | Right-click > Replay XHR | Test if the endpoint works |
| Block request | Right-click > Block URL | See what data disappears from the page |
| Search all requests | Cmd+F in Network tab | Find requests containing specific text |
| Preserve log | Checkbox at top | Keep requests across page navigations |
Identifying Required Headers
Strip headers one at a time to find the minimum set. Start with all headers from DevTools, then remove them to see which ones are actually needed. Common essential headers:
User-Agent, almost always requiredReferer, many APIs check thisAuthorizationorCookie, for authenticated endpointsX-Requested-With, some APIs look for this
For sites with JavaScript challenges that block direct API access, ScrapingAnt renders pages in a real browser and can return the API responses your script needs.
Next Steps
- Reverse engineer complex hidden APIs
- Handle APIs requiring cookies and sessions
- Use Postman for deeper API exploration