Skip to content

Commit d55209d

Browse files
authored
创建腾讯云SCF脚本
1 parent a509376 commit d55209d

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

index_scf.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# -*- coding: utf8 -*-
2+
# 腾讯云SCF脚本,须在在线IDE终端,1- cd src , 2- pip install bs4 -t .
3+
import sys
4+
import io
5+
from urllib import request
6+
import random
7+
from urllib.parse import quote
8+
from bs4 import BeautifulSoup
9+
10+
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8') # 改变标准输出的默认编码
11+
12+
#配置部分
13+
cookie_str = ""
14+
user_page = r''
15+
plus_key = r''
16+
17+
# 登录后才能访问的网站
18+
u1 = 'https://keylol.com/forum.php?mod=guide&view=my'
19+
u2 = 'https://keylol.com/t' + str(random.randint(300000, 731527)) + '-1-1'
20+
# plus webhook地址
21+
u3h = "http://www.pushplus.plus/send/" + plus_key + "?title=" + quote("其乐论坛自动签到", 'utf-8') + "&content="
22+
u3 = ""
23+
24+
25+
def auto(url):
26+
global u3
27+
try:
28+
req = request.Request(url)
29+
# 设置cookie
30+
req.add_header('cookie', cookie_str)
31+
# 设置请求头
32+
req.add_header('User-Agent',
33+
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
34+
35+
resp = request.urlopen(req)
36+
print("已访问:", url, " 状态码:", resp.getcode())
37+
u3 += "已访问:" + url + " 状态码:" + str(resp.getcode()) + "<br>"
38+
except Exception as e:
39+
u3 += e.__str__() + "<br>"
40+
41+
42+
def getCredit(url):
43+
global u3
44+
try:
45+
req = request.Request(url)
46+
# 设置cookie
47+
req.add_header('cookie', cookie_str)
48+
# 设置请求头
49+
req.add_header('User-Agent',
50+
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 '
51+
'Safari/537.36')
52+
53+
resp = request.urlopen(req)
54+
bs = BeautifulSoup(resp.read().decode('utf-8'), "html.parser")
55+
em = bs.findAll('li')[100]
56+
print(em.text)
57+
u3 += em.text + "<br>"
58+
except Exception as e:
59+
u3 += e.__str__() + "<br>"
60+
61+
62+
def pushMsg(url):
63+
req = request.Request(url)
64+
# 设置请求头
65+
req.add_header('User-Agent',
66+
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 '
67+
'Safari/537.36')
68+
resp = request.urlopen(req)
69+
print("推送消息结果:", str(resp.read(), 'utf-8'))
70+
71+
72+
def main_handler(event, context):
73+
global u3
74+
print("其乐自动签到 By Moecola.com")
75+
print("--------------------------")
76+
print("签到开始")
77+
u3 += '签到开始<br>'
78+
getCredit(user_page)
79+
auto(u1)
80+
auto(u2)
81+
print("签到结束")
82+
u3 += '签到结束<br>'
83+
getCredit(user_page)
84+
u3 = quote(u3, 'utf-8')
85+
pushMsg(u3h + u3)

0 commit comments

Comments
 (0)