import json
import time
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from time import sleep
import urllib3
import os, sys
urllib3.disable_warnings()
seleniumChromeDriver = webdriver.Chrome()
seleniumChromeDriver.maximize_window()
returnResponse = []
for pageNumber in range(5):
url = "https://suchen.mobile.de/fahrzeuge/search.html?damageUnrepaired=ALSO_DAMAGE_UNREPAIRED&isSearchRequest=true&od=down&pageNumber=" + str(
pageNumber + 1)
seleniumChromeDriver.get(url)
headers = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'Referer': 'https://suchen.mobile.de/fahrzeuge/search.html?dam=0&isSearchRequest=true&ref=quickSearch&sb=rel&vc=Car',
'Cookie':''
}
response = requests.get(url, headers=headers, verify=False).content
soup = BeautifulSoup(response, "html.parser")
body = soup.find("body", {})
bodyCaptchaChecking = body.find("iframe2", {})
time.sleep(10)
carList = soup.find_all('div', {'class': 'cBox-body cBox-body--resultitem'})
for car in carList:
carName = car.find("span", {"class": "h3 u-text-break-word"}).text.strip()
carPrice = car.find("span", {"class": "h3 u-block"}).text.strip()
carPrice = carPrice.replace("\xa0", " ")
returnResponse.append({
'carName': carName,
'carPrice': carPrice
})
time.sleep(10)
else:
#os.system("RecaptchaSol.py") #Captcha dosyamızı çağırıyoruz.
print('Captcha!')
jsonFormattedString = json.dumps(returnResponse, indent=2)
fileManager = open('result.json', 'a')
fileManager.write(jsonFormattedString)
fileManager.close()
Merhabalar, kodumda herhangi bir hata olmamasına rağmen verileri çekemiyorum. Sebebi ne olabilir