0

I want to login to the web page and find a car by plate. This is my code. I manage to login to page with req but after I make req2 the response I get is login page as I just opened the page and need to log in. There is some kinda problem with my last 'POST' method.

import requests
from bs4 import BeautifulSoup

def get_viewstate():
    url = "https://parking-nbaze.pl/Account/Login.aspx"
    req = requests.get(url)
    data = req.text

    bs = BeautifulSoup(data)
    return bs.find("input", {"id": "__VIEWSTATE"}).attrs['value']

url = "https://parking-nbaze.pl/Account/Login.aspx"
url2 = "https://parking-nbaze.pl/Views/Customers/DoPayment.aspx/Search"
a = get_viewstate()
data = {"__VIEWSTATE": a,
        'Username': 'xxxxx',
        'Password': 'xxxxx'}

req = requests.post(url, data)
# Everything work fine until req2
data.update({"plate":"IRT139"})

req2 = requests.post(url2, data)

bs = BeautifulSoup(req.text)

I tried to debug with Fiddler and this is how successful post method looks in it.

POST https://parking-nbaze.pl/Views/Customers/DoPayment.aspx/Search HTTP/1.1
Host: parking-nbaze.pl
Connection: keep-alive
Content-Length: 18
Origin: https://parking-nbaze.pl
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Content-Type: application/json; charset=UTF-8
Accept: */*
Referer: https://parking-nbaze.pl/Views/Customers/DoPayment.aspx
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en;q=0.9,ru-RU;q=0.8,ru;q=0.7,lt-LT;q=0.6,lt;q=0.5,en-US;q=0.4,nl;q=0.3,de;q=0.2
Cookie: __AntiXsrfToken=13dbecb5a7404b5e92e0f6f820add8bf; User=xxxxx; .ASPXAUTH=7A100A0B47D5B3E91DF5FE154A7FC4F1A2FB4BCC8748CE5C3CD26E5396571C592123E2E3605195E8D33FCD87B8FF9DE9B3F86342C8C2604A996C46F8DAC64AFA00C0F17124F0001927FA4E1B375733C379BB4E2FB608EA2F306D3B848F15D2FB7EE948BCFF0171B9F4618493C323FAA866F30F0ACE8DFE4C5918ACBC549863C7D96229BEE7705AED854E443343C06B28

{"plate":"IRT139"}
Chaban33
  • 1,362
  • 11
  • 38

0 Answers0