"
# Target AutoScout24 listing URL
target_url = urllib.parse.quote_plus("https://www.autoscout24.ch/de/d/porsche-911-coupe-38-turbo-pdk-12188643")
# Optional parameters
render = "true"
geo_code = "ch"
# Scrape.do API endpoint
url = f"https://api.scrape.do/?token={token}&url={target_url}&geoCode={geo_code}&render={render}"
# Send the request
response = requests.request("GET", url)
# Parse the response using BeautifulSoup
soup = BeautifulSoup(response.text, "html.parser")
# Extract car name
title = soup.find("h1").text.strip()
print("Car Name:", title)
```
**Expected Output:**
```yaml
Car Name: PORSCHE 911 Coupé 3.8 Turbo PDK
```
By targeting the **first `` tag**, we efficiently extract the car model name without needing to specify class attributes.
### Extracting the Car Price
With the **car name** successfully extracted, the next step is to retrieve the **listing price,** which is the most important information on this page.
Initially, I've attempted to locate the price using a specific `
` tag with a predefined class. However, AutoScout24 dynamically assigns class names, which can change over time, making class-based extraction unreliable.
Instead, I've taken a **more flexible approach** by searching for the price text directly. Since all car prices on AutoScout24 include **"CHF" followed by a number**, we can use **regular expressions (re module)** to locate and extract it anywhere in the page content.
```python
from bs4 import BeautifulSoup
import requests
import urllib.parse
import re
# Our token provided by Scrape.do
token = ""
# Target AutoScout24 listing URL
target_url = urllib.parse.quote_plus("https://www.autoscout24.ch/de/d/porsche-911-coupe-38-turbo-pdk-12188643")
# Optional parameters
render = "true"
geo_code = "ch"
# Scrape.do API endpoint
url = f"https://api.scrape.do/?token={token}&url={target_url}&geoCode={geo_code}&render={render}"
# Send the request
response = requests.request("GET", url)
# Parse the response using BeautifulSoup
soup = BeautifulSoup(response.text, "html.parser")
# Extract car name
title = soup.find("h1").text.strip()
# Search for the first occurrence of "CHF" followed by a number
match = re.search(r"CHF\s([\d'.,]+)", soup.get_text())
# Extract and clean the price if found
price = match.group(0).replace("\xa0", " ") if match else "Price not found"
print("Car Name:", title)
print("Car Price:", price)
```
***Why does this work?***
✅ **Avoids dependency on class names** that might change dynamically.
✅ **Searches the entire page text**, ensuring the price is found even if the structure varies.
✅ **Uses regular expressions (`re`)** to precisely extract numbers that follow "CHF".
*And here's the expected output:*
```yaml
Car Name: PORSCHE 911 Coupé 3.8 Turbo PDK
Car Price: CHF 106,890.-
```
This approach ensures that **even if AutoScout24 updates its HTML structure, the price extraction will continue working reliably**.
## Conclusion
Scraping AutoScout24 is difficult due to **Akamai bot protection and dynamic HTML structures**, which block traditional scrapers and make extracting data unreliable.
We successfully extracted the **car name and price** by bypassing these obstacles with Scrape.do. Instead of relying on unstable class names, we used **regular expressions** to locate the price anywhere on the page, ensuring a more flexible and robust approach.
If you need to scrape AutoScout24 without getting blocked, **Scrape.do makes it simple**.
[Get **1000 free API calls** and start now.](https://scrape.do) 🚀