無法使用 POST 請求登入網站
P粉087951442
P粉087951442 2023-09-08 12:18:17
0
1
473

我嘗試使用 python 的 POST 要求登入 https://admin.raptor.software,但無法登入。

我正在使用以下程式碼片段:

import requests_html

session = requests_html.HTMLSession()

r = session.get('https://admin.raptor.software')
csrf = r.html.xpath('/html/head/meta[4]')[0].attrs['content']

data = {
    'client_id': '2',
    'client_secret': csrf,
    'grant_type': 'password',
    'password': 'MYPASSWORD',
    'username': 'MYEMAIL'
}
session.post('https://admin.raptor.software/api/login', data = data)

我需要用它來發布 csrf,因此我使用 requests_html 函式庫來取得它。

成功登入後,我希望使用以下程式碼列印儀表板 HTML,但它在上面發布了登入頁面 HTML:

r = session.get('https://admin.raptor.software/dashboard')
print(r.text)
<!doctype html>
<html lang="de">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0">
        <meta name="csrf-token" content="eFC7HQfM9NJdi8u1nxQjDubUNjLLjVrmVmM1T4mD">
        <link href="/css/app.css?id=39d4a60bbe483994f0ec" rel="stylesheet">
        <title>Admin</title>

        <!-- Fonts -->
        <link rel="dns-prefetch" href="//fonts.gstatic.com">
        <link rel="preconnect" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

        <!-- Styles -->
        <link href="https://admin.raptor.software/css/app.css" rel="stylesheet">
        <link href="https://admin.raptor.software/css/modules.css" rel="stylesheet">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
    </head>
    <body>
        <div id="app">
            
        </div>
        
        <script src="/js/app.js?id=3f08b75b370e0e33ea8b"></script>
        <script src="/js/modules.js?id=65903b83a0bc6fc9f233"></script>
    </body>
</html>

P粉087951442
P粉087951442

全部回覆(1)
P粉005134685

嘗試使用

import requests
session = requests.Session()
r = session.post("https://website.com/example/login", data={
"username": "username here",
"password": "password here"
})
r = session.get("https://website.com/example/dashboard")
print(r.text)

這個腳本的作用是,它按照您的腳本執行所有操作,但我使用 requests 而不是 requests_html

我在 Google 和其他平台上嘗試了我的腳本,它成功了。

希望有用!

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!