用win服务器的浏览器登录也没有问题。所以就很奇怪。到底是哪里有问题。
[Python] 纯文本查看 复制代码import requests
import mysql.connector
import json
import time
# 创建一个会话
session = requests.Session()
API_KEY = "xxxxxxxxxxxxxxxxxxx"
SECRET_KEY = "xxxxxxxxxxxx"
def get_access_token():
"""
使用 AK,SK 生成鉴权签名(Access Token)
:return: access_token,或是None(如果错误)
"""
url = "https://aip.baidubce.com/oauth/2.0/token"
params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
return str(requests.post(url, params=params).json().get("access_token"))
def words(): #获取验证码
url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=" + get_access_token()
payload = 'url=https%3A%2F%2F模拟网址.com%2Fusers%2FcheckCode.htm%3Fid% + ts'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
response_json = response.json()
words = response_json["words_result"][0]["words"]
print(words)
return words
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"Connection": "keep-alive",
"Content-Length": "103",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "模拟网址.com",
"Origin": "https://模拟网址.com",
"Referer": "https://模拟网址.com/users/usr/blacklist/list.htm",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.31",
"X-Requested-With": "XMLHttpRequest",
"sec-ch-ua": "\"Microsoft Edge\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\""
}
data = {
"newPlatform": "2",
"redirectURL": "",
"platUserId": "",
"platMobile": "",
"platServerId": "",
"userName": "xxxx",
"password": "xxxxx",
"corpCode": "xxxxxx",
"checkCode": words(),
"rememberInfo": "true",
}
url = "https://模拟网址.com/users/logining.htm"
response = session.post(url, headers=headers, data=data)
if response.status_code == 200:
print(response.text)
#return True
else:
print("Login failed.")
#return False
data = {
"blackList.id": "",
"blackList.type": "certificateNo",
"fruit": "White",
# 以下为引用遍历的身份证号
"blackList.typeVal": "12312132121213",
"groupId": "684",
}
url = "https://模拟网址.com/users/usr/blacklist/doAddorEditblack.htm"
response = session.post(url, headers=headers, data=data)
print(response.text)