I can’t get the correct answer when work with cookies and few POST/GET req

46 views Asked by At

I'm trying to parse the site - https://rentcar.gr/en/booking/cars as I understood in the developer panel, I must first set up a post and then get a request to get the desired page, but I ran into a problem in my opinion with cookies

This is screen from developer panel of this requests(post -> get)

enter image description here enter image description here enter image description here

This my code firstly a get page for get token and take cookies, then use this data for POST req and save cookies, then use this cookies for get req but get wrong content looking at it, it seems to me that this is the code for the main page of the site

from requests import Session
from bs4 import BeautifulSoup

api_url = "https://rentcar.gr/en/booking/cars"

work = Session()

req = work.get(api_url)

soup = BeautifulSoup(req.content, "html.parser")
token = soup.find('form').find('input').get('value')

data = {
    '_token': token,
    'pickUpLocation': '8',
    'pickUpDate': '22-02-2024',
    'pickUpTime': '10:00',
    'dropOffLocation': '6',
    'dropOffDate': '29-02-2024',
    'dropOffTime': '10:00',
    'driverAge': '25',
    'carID': '0',
    'minPickUpDate': '22-02-2024',
    'minDropOffDate': '22-02-2024',
}
req = work.post(api_url, cookies=req.cookies, data=data)
    
soup = BeautifulSoup(
    work.get(api_url, cookies=req.cookies).content, "html.parser"
)

for h3 in soup.select("h3.carname"):
    print(f'{h3.text:<60}')
1

There are 1 answers

3
Tanveer On

second Api give you a response in HTML format.

soup = BeautifulSoup(
    work.get(api_url, cookies=req.cookies).content, "html.parser"
)
for h3 in soup.find_all('h3'):
    print(h3.text)

enter image description here