|
import re |
|
|
|
import requests |
|
from bs4 import BeautifulSoup |
|
|
|
# 赠送的网址(post) |
|
exchange_url = "http://www.nexushd.org/mybonus.php?action=exchange" |
|
|
|
# 98的帖子网址 |
|
cc98_url = "http://www.cc98.org/dispbbs.asp" |
|
board_id = 744 |
|
post_id = 4716223 |
|
|
|
# 用户信息(不同用户此处不同) |
|
cookie = "" |
|
|
|
# 头信息,最重要的是Cookie的设置,其代表自己的用户信息,更新该部分即可为另一个用户更新 |
|
headers = { |
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", |
|
"Accept-Encoding": "gzip, deflate", |
|
"Accept-Language": "en,zh-CN;q=0.8,zh;q=0.6,zh-TW;q=0.4,en-GB;q=0.2,ja;q=0.2", |
|
"Cache-Control": "max-age=0", |
|
# "Connection": "keep-alive", |
|
# "Content-Length": "35", |
|
# "Content-Type": "application/x-www-form-urlencoded", |
|
"Cookie": cookie, |
|
"DNT": "1", |
|
"Host": "www.nexushd.org", |
|
"Origin": "http://www.nexushd.org", |
|
"Referer": "http://www.nexushd.org/mybonus.php", |
|
"Upgrade-Insecure-Requests": "1", |
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " |
|
"Chrome/56.0.2924.87 Safari/537.36", |
|
} |
|
|
|
session = requests.session() |
|
session.headers = headers |
|
|
|
|
|
def get_current_magic_point(): |
|
pa_magic = '\[<a href="mybonus.php">使用</a>\]: ([0-9.,]+)' |
|
|
|
# 获取最初魔力值 |
|
res = session.get('http://www.nexushd.org/mybonus.php') |
|
text = res.text |
|
|
|
magic = re.search(pa_magic, text).group(1) |
|
|
|
return magic |
|
|
|
|
|
def exchange(idx, user, amount, message): |
|
old_magic = get_current_magic_point() |
|
|
|
# 发送请求 |
|
res = session.post(exchange_url, { |
|
"option": 7, |
|
"username": user, |
|
"bonusgift": amount, |
|
"message": message + "from auto exchange script powered by 风之凌殇", |
|
"submit": "赠送" |
|
}) |
|
|
|
text = res.text |
|
|
|
current_magic = get_current_magic_point() |
|
|
|
# print(old_magic, current_magic) |
|
|
|
from datetime import datetime |
|
current_time = datetime.now() |
|
if current_magic != old_magic: |
|
print("{idx:4d}: 向{user:^20s}赠送了{amount:^5d}个魔力值,赠送前魔力值为{old:^15s},赠送后剩余魔力值为{remain:^15s},赠送于{now}".format( |
|
idx=idx, |
|
user=str(user), |
|
amount=amount, |
|
old=old_magic, |
|
remain=current_magic, |
|
now=current_time |
|
)) |
|
else: |
|
print("{idx:4d}: 向{user:^20s}赠送失败,赠送前魔力值为{old:^15s},赠送后剩余魔力值为{remain:^15s},赠送于{now}".format( |
|
idx=idx, |
|
user=str(user), |
|
amount=amount, |
|
old=old_magic, |
|
remain=current_magic, |
|
now=current_time |
|
)) |
|
pass |
|
|
|
|
|
def batch_exchange(amount=5000, message="test", users_path='users.yaml', get_realtime_users=False): |
|
if get_realtime_users: |
|
users = get_users(dump=False) |
|
else: |
|
# load exchange users from exchange.yaml |
|
import yaml |
|
with open(users_path, encoding='utf-8') as users_f: |
|
users = yaml.load(users_f) |
|
|
|
print(users) |
|
for idx, user in enumerate(users): |
|
exchange(idx + 1, user, amount, message) |
|
# time.sleep(1) |
|
pass |
|
|
|
|
|
def get_pages(): |
|
res = requests.get(cc98_url, { |
|
"boardID": board_id, |
|
"ID": post_id, |
|
"page": "", |
|
"replyID": post_id, |
|
"star": 1 |
|
}) |
|
|
|
pa_pages = "本主题贴数 <b>(\d+)</b>" |
|
total = int(re.search(pa_pages, res.text).group(1)) |
|
pages = (total + 9) // 10 |
|
|
|
print('total post count: {post_count}, total pages: {pages}'.format( |
|
post_count=total, |
|
pages=pages |
|
)) |
|
|
|
return pages |
|
|
|
def unique(seq): |
|
seen = set() |
|
seen_add = seen.add |
|
return [x for x in seq if not (x in seen or seen_add(x))] |
|
|
|
def get_users(dump=True): |
|
users = [] |
|
for page in range(1, get_pages() + 1): |
|
res = requests.get(cc98_url, { |
|
"boardID": board_id, |
|
"ID": post_id, |
|
"page": "", |
|
"replyID": post_id, |
|
"star": page |
|
}) |
|
|
|
text = res.text |
|
# print(text) |
|
selector = 'td.content-cell-v1 > div' |
|
|
|
soup = BeautifulSoup(text, 'lxml') |
|
# 1 |
|
for idx, reply in enumerate(soup.select(selector)): |
|
# print(reduce(lambda s,a: s+a,[str(c) for c in reply.children])) |
|
reply = re.sub(r"(xx|xiexie ?)?lz|id(:|:|=)|gxgx|nh(d|g)(id)?(:|:| )|ym| |\[/?.+\]", "", |
|
re.sub(r"thx", "", reply.text, flags=re.IGNORECASE), |
|
flags=re.IGNORECASE) |
|
# print(reply) |
|
user_id = re.search('[a-zA-Z0-9.-]{3,}', reply) |
|
if user_id: |
|
print(10 * (page - 1) + idx + 1, user_id.group()) |
|
users.append(user_id.group()) |
|
# print('******************我是一条萌萌的分隔线******************') |
|
# print() |
|
users = unique(users) |
|
if dump: |
|
import yaml |
|
with open('users_full.yaml', 'w', encoding='utf-8') as save: |
|
yaml.dump(users, save) |
|
else: |
|
from pprint import pprint |
|
pprint(sorted(users)) |
|
|
|
print("total count: %d" % len(users)) |
|
return users |
|
pass |
|
|
|
|
|
def main(): |
|
global cookie, board_id, post_id |
|
|
|
print('------------------------------------------' |
|
'------友情提示:使用前请阅读readme.md------' |
|
'------------------------------------------') |
|
cookie = input('请输入cookie: ') |
|
board_id = input('请输入board_id:') |
|
post_id = input('请输入帖子id:') |
|
|
|
message = input('请输入赠送附带的消息内容:') |
|
magic_amount = int(input('请输入每人赠送的魔力值的个数:')) |
|
|
|
batch_exchange(magic_amount, message, get_realtime_users=True) |
|
pass |
|
|
|
|
|
if __name__ == '__main__': |
|
# batch_exchange(2000, '喵喵喵喵喵', get_realtime_users=True) |
|
get_users(dump=False) |
|
# main() |
|
# print(get_pages()) |
|
# print(re.search('[a-zA-Z0-9]+', "谢谢楼主bitch007好人一生平安[right][color=gray]From MI 6 via MyCC98[/color][/right]")) |
|
# print(re.match('a{3,}', 'aaaaaabbb')) |
|
|
|
# import yaml |
|
# with open('users.yaml', encoding='utf-8') as users_f: |
|
# users = yaml.load(users_f) |
|
# users = [1,1,1,2,3,4,5] |
|
# print(users) |
|
# print(list(set(users))) |
|
pass |
这个正则厉害了