Python 如何为登录请求生成UserLoginType[\u令牌]

Python 如何为登录请求生成UserLoginType[\u令牌],python,python-requests,token,Python,Python Requests,Token,我正在尝试使用如下post请求登录网站: import requests cookies = { '_SID': 'c1i73k2mg3sj0ugi5ql16c3sp7', 'isCookieAllowed': 'true', } headers = { 'Host': 'service.premiumsim.de', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/2

我正在尝试使用如下post请求登录网站:

import requests

cookies = {
    '_SID': 'c1i73k2mg3sj0ugi5ql16c3sp7',
    'isCookieAllowed': 'true',
}

headers = {
    'Host': 'service.premiumsim.de',
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'Referer': 'https://service.premiumsim.de/',
    'Content-Type': 'application/x-www-form-urlencoded',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1',
}

data = [
  ('_SID', 'c1i73k2mg3sj0ugi5ql16c3sp7'),
  ('UserLoginType[alias]', 'username'),
  ('UserLoginType[password]', 'password'),
  ('UserLoginType[logindata]', ''),
  ('UserLoginType[_token]', '1af70f3d0e5b9e6c39e1475b6d84e9d125d076de'),
]

requests.post('https://service.premiumsim.de/public/login_check', headers=headers, cookies=cookies, data=data)
问题是参数中的“UserLoginType[\u token]。上面的代码正在运行,但我没有这个令牌,也不知道如何生成它。因此,当我执行请求时,我在不使用_令牌的情况下执行请求,请求失败。 谷歌没有找到任何关于UserLoginType的有用信息

是否有人知道如何生成它(例如,首先使用另一个请求)以便能够登录

编辑: 感谢t.m.adam的建议,我使用bs4获得代币:

import requests
from bs4 import BeautifulSoup as bs

tokenRequest = requests.get('https://service.premiumsim.de')
html_bytes = tokenRequest.text
soup = bs(html_bytes, 'lxml')
token = soup.find('input', {'id':'UserLoginType__token'})['value']

您可以使用
bs4
lxml
获取它。您可以使用
bs4
lxml