本帖最后由 hysaoh 于 2022-9-7 18:28 编辑
本帖最后由 hysaoh 于 2022-9-7 18:28 编辑
目标网站HDsay
签到目的:HDsay高清乐园拥有大量的影视资源,但是需要购买金币进行付费,此脚本可以通过模拟签到获得金币。因为回复帖子可能污染该网站环境,因此没有开发自动回复功能。
代码如下:
import json
import random
import time
from bs4 import BeautifulSoup
import arrow
import requests
import urllib3
urllib3.disable_warnings()
Greetings = ["开通VIP全站资源免金币免回复快速下载!",
"日出而作兮日入归,如彼草木兮雨露肥。",
"幸福,是清晨的一句问候,一个微笑,或一个拥抱。早安!",
"万木沉酣新雨后,百昌苏醒晓风前。",
"满堂谁是知音者,不惜千金与莫愁。",
"衣带渐宽终不悔,为伊消得人憔悴。",
"我会照顾好我棕黑色的头发,挑剔的胃和爱笑的眼睛。",
"一点朱砂,两方罗帕,三五鸿雁,乱了四季扬花。六弦绿漪,七星当挂,八九分相思,懒了十年琵琶。",
"曾经以为过不去的,终究会过去,痛苦有时候是一种提升。",
"人活在世上,总免不了一些为难自己或看自己不顺眼的人。",
"多情自古空余恨,好梦由来最易醒。",
"贪图省力的船夫,目标永远下游。",
"浮华一生,淡忘一季,空有回忆,打乱缠绵。",
"宠辱不惊,看庭前花开花落;去留无意,望天空云卷云舒。",
"抽刀断水水更流,举杯消愁愁更愁。",
"阳光温热,岁月静好,你还不来,我怎敢老去?",
"有朋自远方来,没带特产。",
"男儿有泪不轻弹,只是未到伤心处。",
"一个好的女朋友,能帮你的电脑省下200G硬盘噢。",
"这年头不缺爱情,缺的是把爱情当回事的人。",
"心甘情愿才能理所当然,理所当然才会义无反顾。",
"仰天大笑出门去,我辈岂是蓬蒿人。"]
def get_headers(session):
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/104.0.0.0 "
"Safari/537.36",
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Content-Type': 'application/json',
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cache-Control": "no-cache",
"X-Requested-With": "XMLHttpRequest",
"X-XSRF-TOKEN": session.cookies.get("XSRF-TOKEN"),
"Referer": "https://www.hdsay.net/Account/Login",
}
return headers
def do_work(user, pwd):
print("-----------------")
print("开始登录%s" % user)
dataclasses = {"OriginalUrl": "https://www.hdsay.net/", "RememberMe": "false",
"UsernameOrEmailAddress": user, "Password": pwd}
session = requests.session()
session.get("https://www.hdsay.net/Account/Login", headers={
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/104.0.0.0 "
"Safari/537.36"},
verify=False)
headers = get_headers(session)
post = session.post("https://www.hdsay.net/account/loginsubmit", headers=headers, timeout=10,
verify=False,
data=json.dumps(dataclasses))
print("登录结果:", post.status_code)
# 请求主页,获取uid
session_get2 = session.get("https://www.hdsay.net", timeout=3, verify=False)
soup = BeautifulSoup(session_get2.text, "html.parser")
num = soup.select("#heinfo > div.wrapper.head-info > div.inline-item.photo > a")[0].get("href").find("=")
userid = soup.select("#heinfo > div.wrapper.head-info > div.inline-item.photo > a")[0].get("href")[num + 1::]
session_get = session.get("https://www.hdsay.net/member/sign", timeout=10, verify=False)
print("主界面请求:", session_get2.status_code)
print("签到界面请求:", session_get.status_code)
num = random.randint(1, 10)
now = str(arrow.now())
ran = random.randint(1, len(Greetings))
context = {"isActive": True, "creatorUserName": None, "creationTime": now,
"lastModifierUserName": None, "lastModificationTime": None, "moodName": xinqing[num],
"inputModeName": "自己填写", "userId": int(userid), "mood": num,
"moodWords": Greetings[ran - 1],
"inputMode": "2", "description": None,
"version": 0,
"id": "00000000-0000-0000-0000-000000000000",
"__RequestVerificationToken": session.cookies.get("XSRF-TOKEN")}
headers2 = get_headers(session)
response = session.post("https://www.hdsay.net/api/services/app/ForumMemberSign/Create",
headers=headers2,
timeout=10, verify=False, data=json.dumps(context))
response.encoding = "GB2312"
if response.status_code == 200:
print("签到成功")
return True
if response.status_code == 500:
print("已经签到过了")
return True
else:
print("签到失败,未知错误")
return False
if __name__ == '__main__':
# 在此填写用户名密码
# 示例如下
# username_and_password = {"user1": "passwd1",
# "user2": "passwd2"}
username_and_password = {"user": "passwd"
}
xinqing = {1: "cl", 2: "开心", 3: "难过", 4: "偷笑", 5: "愤怒", 6: "擦汗", 7: "鄙视",
8: "大哭", 9: "慵懒", 10: "无聊"
}
for username, password in username_and_password.items():
while True:
try:
if do_work(username, password):
print(username + "签到成功")
break
else:
print(username + "签到失败")
break
except Exception as e:
print(e)
time.sleep(5)
continue