这是一个从psn中文站获取游戏成就列表的程序
需要自己改游戏网址,下面是以celeste为例
"""
Author: Sprite
Date: 2022/5/10 19:30
Have a nice day ~~~~~
"""
import requests
from json import loads
import os
import csv
from re import search, findall
def fake_ip():
global Headers
Headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36'
}
URL = 'http://d.jghttp.alicloudecs.com/getip?num=1&type=2&pro=&city=0&yys=0&port=1&pack=48158&ts=0&ys=0&cs=0&lb=1&sb=0&pb=45&mr=1®ions='
resp = requests.get(url=URL, headers=Headers)
ip_data = loads(resp.text)['data'][0]
fake_ip = f'{ip_data["ip"]}:{ip_data["port"]}'
proxy = {
'http': f'http://{fake_ip}',
'https': f'http://{fake_ip}'
}
return proxy
def origin_text(website, proxy):
resp = requests.get(url=website, headers=Headers, proxies=proxy)
if resp.status_code == 200:
resp.encoding = 'utf-8'
return resp.text
else:
print(resp.status_code)
return resp.status_code
def get_name(info):
return search(r'(.+?) ', info).group(1)
def create_file(game_name):
if not os.path.exists(f'{game_name}.csv'):
csv.writer(open(f'{game_name}.csv', 'w', encoding='utf-8', newline='')).writerow(['成就名', '成就说明', '评论区链接', '完成百分比'])
def get_target_info(info):
re_info1 = r'(?s)(.+?) '
info1 = findall(re_info1, info)
result = []
for x in info1:
re_info2 = r'(?s) \
r'>(.+?).*' \
r'(.+?).*' \
r'\n (.+?)\n '
info2 = findall(re_info2, x)[0]
info2 = [info2[1], info2[2], info2[0], info2[3]]
result += [info2]
return result
if __name__ == '__main__':
fake_ip = fake_ip()
origin_info = origin_text('https://psnine.com/psngame/14979', fake_ip)
game_name = get_name(origin_info)
create_file(game_name)
result = get_target_info(origin_info)
csv.writer(open(f'{game_name}.csv', 'a', encoding='utf-8', newline='')).writerows(result)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)