登录以及获取信息测试

This commit is contained in:
YueL1331
2026-01-16 15:15:33 +08:00
commit ee89284a4c
2 changed files with 147 additions and 0 deletions

56
登录测试.py Normal file
View File

@ -0,0 +1,56 @@
import requests
# 1. 准备登录信息
login_url = "http://111.198.24.44:88/index.php"
# 这是你刚刚抓到的 Payload 数据
payload = {
"error": "",
"login_theme": "newskin",
"module": "Users",
"action": "Authenticate",
"return_module": "Users",
"return_action": "Login",
"user_name": "TEST", # 在这里填入真实的用户名
"user_password": "test", # 在这里填入真实的密码
"code": "",
"user_validate": ""
}
# 伪装成浏览器(这很重要,防止被反爬虫拦截)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
# 2. 创建一个 Session (会话)
# Session 的作用就像一个浏览器窗口,它会自动保存 Cookie
session = requests.Session()
try:
# 3. 发送登录请求
# allow_redirects=True 会自动跟随 301 跳转到主页,就像浏览器一样
response = session.post(login_url, data=payload, headers=headers, allow_redirects=True)
# 4. 检查结果
print(f"状态码: {response.status_code}")
# 获取到的 Cookie
print("获取到的 Cookies:")
print(session.cookies.get_dict())
# 简单的验证:如果返回的网页里包含了'退出'或用户名的字样,说明登录成功了
if "logout" in response.text.lower() or "退出" in response.text:
print("\n==> 登录成功! <==")
# 【进阶】: 登录成功后,你可以直接用这个 session 访问其他页面
# 比如访问主页获取数据,它会自动带上刚才拿到的 cookie
# home_page = session.get("http://111.198.24.44:88/index.php?module=Home&action=index")
# print(home_page.text[:200])
else:
print("\n可能登录失败,请检查用户名密码。")
# 如果失败,打印一部分返回内容看看原因
print("返回内容预览:", response.text[:500])
except Exception as e:
print(f"发生错误: {e}")