[Python] 纯文本查看 复制代码 # This is a sample Python script.
import random
import string
import re
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import requests
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
def generate_random_number(length):
# 从数字0-9中随机选择,并生成指定长度的随机数
return ''.join(random.choices(string.digits, k=length))
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
rand_str = generate_random_number(17)
img = requests.get('https://hetungongying.cn/code?randomStr=' + rand_str) # 这里获取到验证码
with open('downloaded_image.jpg', 'wb') as file: # 吧验证码保存到本地文件
file.write(img.content)
Clientid = requests.get('https://hetungongying.cn/js/app.js')
pattern = r"Basic\s+([a-zA-Z0-9=]+)"
rc = Clientid.text
match = re.findall(pattern, rc)
Clientid = match[0]
print(Clientid)
code = input()
# 账号密码改成自己的。密码加密自己解决。
url = 'https://hetungongying.cn/auth/oauth/token?username=15555555555&password=S%2BALIs5ulAlgwrcRLgClrw%3D%3D&randomStr=' + rand_str + '&code=' + code + '&grant_type=password&scope=server'
print(url)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36',
'Authorization': 'Basic ' + Clientid,
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' # 这个要加,不然返回的就不是中文的了。
}
response = requests.get(url, headers=headers)
print(response)
print(response.content.decode('utf-8'))
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|