Python Forum
What is the error of not being able to pull data in this code? i didn't see an error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the error of not being able to pull data in this code? i didn't see an error?
#1
import json
import time
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from time import sleep

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)
    #allCookies = seleniumChromeDriver.get_cookies()
    #cookies = ''
    #for cookie in allCookies:
     #   cookies += cookie['name'] + '=' + cookie['value']
      #  if allCookies.index(cookie) != (len(allCookies) - 1):
       #     cookies += ';'
    # time.sleep(10)
    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': ' **doh** '
    }
    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("div", {"class": "cBox--resultList"}).find_all("div", {"cBox-body--resultitem"})
    for car in carList:
        carName = car.find("span", {"class": "h3 u-text-break-word"}).text
        carPrice = car.find("span", {"class": "h3 u-block"}).text
        carPrice = carPrice.replace("\xa0", " ")
        returnResponse.append({
            'carName': carName,
            'carPrice': carPrice
        })
        time.sleep(100)
    else:
        print('Sistem Captcha\'ya Takıldı!')
jsonFormattedString = json.dumps(returnResponse, indent=2)
fileManager = open('result.json', 'a')
fileManager.write(jsonFormattedString)
fileManager.close()
Reply
#2
please post error traceback (complete and unaltered)
Reply
#3
Error:
InvalidHeader: Invalid leading whitespace, reserved character(s), or returncharacter(s) in header value: ' **doh** '
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python output didn't write properly mdmsd2 1 1,923 Aug-16-2023, 12:38 PM
Last Post: Gaurav_Kumar
  google sheet recheck data error ! puttimet38 2 2,222 Mar-21-2021, 04:24 AM
Last Post: puttimet38
  error HTTP Error 403: Forbidden local_bit 1 2,832 Nov-14-2020, 11:34 AM
Last Post: ndc85430
  error in code web scraping alexisbrunaux 5 3,798 Aug-19-2020, 02:31 AM
Last Post: alexisbrunaux
  error zomato scraping data syxzetenz 3 3,360 Jun-23-2020, 08:53 PM
Last Post: Gribouillis
  pull data from python web yunussyes 2 7,715 Mar-22-2020, 06:35 AM
Last Post: yunussyes
  urllib.error.HTTPError: HTTP Error 404: Not Found ckkkkk 4 8,719 Mar-03-2020, 11:30 AM
Last Post: snippsat
  non-finite value error when cleaning data yokaso 0 3,334 Dec-17-2019, 07:26 AM
Last Post: yokaso
  Python/BeautiifulSoup. list of urls ->parse->extract data to csv. getting ERROR IanTheLMT 2 3,970 Jul-04-2019, 02:31 AM
Last Post: IanTheLMT
  Scraping data saving to DB error with Cursor cubangt 3 2,779 May-20-2019, 08:30 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020