自动获取cookie & authorization 字段 并填写至请求包(requests)

如题,想要自动化,python requests
例:www.lanzoux.com/b0jfu6ch
尝试了许久,搜索未得到结果
它本身不需要登陆,但这两个认证都有,我想要的是运行输入想要的软件的关键词,则可以出现相关结果。

现在的代码:
import urllib3
from urllib3 import exceptions
from urllib import parse
urllib3.disable_warnings()
urllib3.disable_warnings(exceptions.InsecureRequestWarning)
proxies = {
‘http’: ‘http://127.0.0.1:8080',
‘https’: ‘http://127.0.0.1:8080'
}
url = ‘www.lanzoux.com/search/s.php'
UserAgent = UserAgent().ie
headers = {
‘Cookie’: ‘codelen=1; Hm_lvt_fb7e760e987871d56396999d288238a4=1657271673; uz_distinctid=181dd16e4bf41e-084355ba7f691d-26021a51-151800-181dd16e4c0ed4’,
‘User-Agent’: UserAgent,
‘Referer’: ‘www.lanzoux.com/b0jfu6ch',
‘Content-Type’: ‘application/x-www-form-urlencoded’
}
a = parse.quote(‘电影’)
data = ‘wd=’ + a + ‘&sign=CDtaOVszDmoDYlE%2BC3BUZlY7Um5WO1ZhBTVWfwJxADFUewVjDWYGZFQ3C28DZV1sA2oDNAVtBCkFMg%3D%3D’
res = requests.post(url, data=data, verify=False, headers=headers, proxies=proxies)
param = res.text
print(param)

headers = {‘Authorization’: param,
“User-Agent”: “Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0”}

result = requests.get(url, headers=headers, verify=False)
print(result.json())

最佳答案

sign 网页中动态获取,可以试试,包括获取软件列表也一样!

import requests
import re
import json
import pprint
from urllib.parse import urlencode


url = 'https://www.lanzoux.com/b0jfu6ch'
header = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.37'
}
resp = requests.get(url, headers=header)
temp = re.findall("'sign':'(.*?)',",resp.text)[0]
print(temp)
header = {
    'accept': 'application/json, text/javascript, */*',
    'content-type': 'application/x-www-form-urlencoded',
    'cookie': 'codelen=1',
    'origin': 'https://www.lanzoux.com',
    'referer': 'https://www.lanzoux.com/b0jfu6ch',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.37',
    'x-requested-with': 'XMLHttpRequest'
}
url = 'https://www.lanzoux.com/search/s.php'
title = '快影'
data = {
    'wd': title,
    'sign': temp
}
print(urlencode(data))
re1 = requests.post(url,data=urlencode(data),headers=header)
json_1 = json.loads(re1.text)
pprint.pprint(json_1)
1个月前 评论
quinn_ (楼主) 1个月前
讨论数量: 3

sign 网页中动态获取,可以试试,包括获取软件列表也一样!

import requests
import re
import json
import pprint
from urllib.parse import urlencode


url = 'https://www.lanzoux.com/b0jfu6ch'
header = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.37'
}
resp = requests.get(url, headers=header)
temp = re.findall("'sign':'(.*?)',",resp.text)[0]
print(temp)
header = {
    'accept': 'application/json, text/javascript, */*',
    'content-type': 'application/x-www-form-urlencoded',
    'cookie': 'codelen=1',
    'origin': 'https://www.lanzoux.com',
    'referer': 'https://www.lanzoux.com/b0jfu6ch',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.37',
    'x-requested-with': 'XMLHttpRequest'
}
url = 'https://www.lanzoux.com/search/s.php'
title = '快影'
data = {
    'wd': title,
    'sign': temp
}
print(urlencode(data))
re1 = requests.post(url,data=urlencode(data),headers=header)
json_1 = json.loads(re1.text)
pprint.pprint(json_1)
1个月前 评论
quinn_ (楼主) 1个月前

并且我想要给后来的读者一个图形化自动打开浏览器,键入并搜索的代码:
from selenium import webdriver

调用Keys模块

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
dri = webdriver.Chrome()
dri.get(“https://www.lanzoux.com/b0jfu6ch")

在输入框输入内容

dri.find_element(By.ID, “spcinput”).send_keys(“电影”)

用回车键代替单击操作

dri.find_element(By.ID, “spcinput”).send_keys(Keys.ENTER)

1个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!