Python requests redirected login

Here is the site http://pro.wialon.com/ where I want to log in with the python request module. Entrance and admission is a demonstration.

import requests
with requests.Session()as c:
    url = 'http://pro.wialon.com/'
    payload = dict(user='demo',
                       passw='demo',
                       login_action='login')
    r = c.post(url, data=payload, allow_redirects=True)
    print(r.text)

Honestly, I want to get the report (on the report tab) as an answer. But I can’t figure out how to get in.

+1
source share
1 answer

The URL is incorrect and you are missing the form data, you also need to complete the initial request, send it to the correct URL, and then get http://pro.wialon.com/service.html:

data = {"user": "demo",
    "passw": "demo",
    "submit": "Enter",
    "lang": "en",
    "action": "login"}

 head = {"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"}

with requests.Session() as c:
    c.get('http://pro.wialon.com/')
    url = 'http://pro.wialon.com/login_action.html'
    c.post(url, data=data, headers=head)
    print(c.get("http://pro.wialon.com/service.html").content)

You can see the message in chrome dev tools on the network tab:

enter image description here

post get , .

:

<form class="login_bg_form" id="login_form" action="login_action.html" method="POST">

, bs4:

import requests
from bs4 import BeautifulSoup
from urlparse import urljoin

data = {"user": "demo",
        "passw": "demo",
        "submit": "Enter",
        "lang": "en",
        "action": "login"}

head = {"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"}

with requests.Session()as c:
    soup = BeautifulSoup(c.get('http://pro.wialon.com/').content)
    redir = soup.select_one("#login_form")["action"]
    url = 'http://pro.wialon.com/login_action.html'
    c.post(url, data=data, headers=head)
    print(c.get(urljoin("http://pro.wialon.com/", redir)).content)

, ajax, , , .

0

Source: https://habr.com/ru/post/1683834/


All Articles