700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python requests.get每次都要初始化_如何在Python(GET/POST)409confi中使用“requests”成功登录...

python requests.get每次都要初始化_如何在Python(GET/POST)409confi中使用“requests”成功登录...

时间:2022-10-30 06:13:29

相关推荐

python requests.get每次都要初始化_如何在Python(GET/POST)409confi中使用“requests”成功登录...

通过这个网站登录的正确方法是什么?在

我想使用requests模块登录here。在

到目前为止,我已经做到了:#!/usr/bin/env python

# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtWidgets

import requests

from utils.user_agents import get_random_user_agent

class StudentsWebSession(QtCore.QThread):

def __init__(self, url, _url=None, username=None, password=None, payload=None):

QtCore.QThread.__init__(self)

self.session = requests.Session()

self.ua = get_random_user_agent('desktop')

self.headers_get_one = {

'host': 'studentsweb.teimes.gr',

'user-agent': self.ua,

'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

'accept-language': 'en-US,en;q=0.5',

'accept-encoding': 'gzip, deflate, br',

'connection': 'keep-alive',

'upgrade-insecure-requests': '1'

}

self.headers_post_one = {

'host': 'studentsweb.teimes.gr',

'user-agent': self.ua,

'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

'accept-language': 'en-US,en;q=0.5',

'accept-encoding': 'gzip, deflate, br',

'referer': 'https://studentsweb.teimes.gr/unistudent/login.asp',

'content-type': 'application/x-www-form-urlencoded',

'connection': 'keep-alive',

'upgrade-insecure-requests': '1'

}

self.headers_get_two = {

'host': 'studentsweb.teimes.gr',

'user-agent': self.ua,

'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

'accept-language': 'en-US,en;q=0.5',

'accept-encoding': 'gzip, deflate, br',

'referer': 'https://studentsweb.teimes.gr/unistudent/login.asp',

'connection': 'keep-alive',

'upgrade-insecure-requests': '1'

}

self.url = url

self._url = _url

self.username = username

self.password = password

self.payload = payload

def __del__(self):

self.wait()

def get(self):

with self.session as s:

if not self.payload:

self.payload = {

'userName': self.username,

'pwd': self.password,

'submit1': 'Login',

'loginTrue': 'login'

}

r = s.get(self.url, headers=self.headers_get_one,

params={'lang': 'en-us'})

print(r.content.decode('cp1253'))

#print(r.url)

r = s.post(self.url, headers=self.headers_post_one,

data=self.payload)

#print(r.content.decode('cp1253'))

#print(r.url)

#r = s.get(self._url, headers=self.headers_get_two)

#print(r.content.decode('cp1253'))

#print(r.url)

def run(self):

self.get()

我这样初始化它:

^{pr2}$

其中db是一个包含所有所需信息的字典。在

结果,我收到了一个标题如下的HTML文档(409http代码)

409 Conflict

我认为您必须执行一个简单的GET请求来存储cookies,然后使用所有必需的有效负载、头和cookies执行POST请求。然后,执行GET请求以接收所需的结果。在

以下是上述要求的证明:

我不喜欢使用selenium、headless浏览器以及非线程安全库

如果你需要更多的信息,请不要犹豫去问他们。在

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。