Вы должны go просмотреть первую веб-страницу, чтобы найти все URL-адреса для каждой машины. Затем скачиваем детали автомобиля и разбираем их одну за другой. Я использовал пакет bs4
(beautifulsoup). Приведенный ниже код необходимо адаптировать к вашим потребностям, но идеи здесь:
import requests
import bs4
url = 'https://www.marktplaats.nl/l/auto-s/p/1/#f:10882'
def downloading_and_parsing_url(url):
# Downloading the webpage as text
txt = requests.get(url)
# Parsing the webpage
soup = bs4.BeautifulSoup(txt.text, 'html.parser')
return soup
soup = downloading_and_parsing_url(url)
soup_table = soup.find('ul', 'mp-Listings mp-Listings--list-view')
for car in soup_table.findAll('li'):
# Finding the url for each 'car'
link = car.find('a')
sub_url = 'https://www.marktplaats.nl/' + link.get('href')
# Downloading each url
sub_soup = downloading_and_parsing_url(sub_url)
# Finding the 'div' with id 'car-attributes'
sub_soup = sub_soup.find('div', {'id': 'car-attributes'})
for car_item in sub_soup.findAll('div', {'class': 'spec-table-item'}):
key = car_item.find('span', {'class': 'key'})
value = car_item.find('span', {'class': 'value'})
print(key.text, value.text)
print('\n')
И вывод
Merk & Model: Lako
Bouwjaar: 1996
Uitvoering: 233 C
Carrosserie: Open wagen
Kenteken: OD-31-VD
APK tot: 29 juni 2020
Prijs: € 7.500,00
Merk & Model: RAM
Bouwjaar: 2020
Carrosserie: SUV of Terreinwagen
Brandstof: LPG
Kilometerstand: 70 km
Transmissie: Automaat
Prijs: Zie omschrijving
Motorinhoud: 5.700 cc
Opties:
Parkeersensor
Dodehoekdetectie
Elektrische achterklep
Metallic lak
Panoramadak
Radio
Mistlampen
Adaptive Cruise Control
Keyless entry
Airconditioning
Boordcomputer
Bekleding leder
Stoelverwarming
Trekhaak
Elektrische ramen
Climate control
Emergency brake assist
Isofix
Alarm
Spraakbediening
Navigatiesysteem
Elektrische buitenspiegels
Traction-control
...