|
| 1 | +import time |
| 2 | +import requests |
| 3 | +from lxml import etree |
| 4 | + |
| 5 | + |
| 6 | +class Faker: |
| 7 | + def __init__(self, username: str, password: str): |
| 8 | + self.username = username |
| 9 | + self.password = password |
| 10 | + self.headers = { |
| 11 | + 'authority': 'www.fakerengine.com', |
| 12 | + 'content-type': 'application/x-www-form-urlencoded', |
| 13 | + 'origin': 'https://www.fakerengine.com', |
| 14 | + 'referer': 'https://www.fakerengine.com/', |
| 15 | + } |
| 16 | + self.url = 'https://www.fakerengine.com/wp-json/b2/v1/userMission' |
| 17 | + self.auth = '' |
| 18 | + |
| 19 | + def api(self, fn: str, data: dict, api_type: str = ''): |
| 20 | + if api_type == 'jwt': |
| 21 | + return requests.post(f'https://www.fakerengine.com/wp-json/jwt-auth/v1/{fn}', headers=self.headers, data=data).json() |
| 22 | + else: |
| 23 | + return requests.post(f'https://www.fakerengine.com/wp-json/b2/v1/{fn}', headers=self.headers, data=data).json() |
| 24 | + |
| 25 | + def login(self): |
| 26 | + data = { |
| 27 | + 'number': '4', |
| 28 | + 'width': '186', |
| 29 | + 'height': '50' |
| 30 | + } |
| 31 | + res = self.api('getRecaptcha', data) |
| 32 | + token = res['token'] |
| 33 | + data = { |
| 34 | + 'nickname': '', |
| 35 | + 'username': self.username, |
| 36 | + 'password': self.password, |
| 37 | + 'code': '', |
| 38 | + 'img_code': '', |
| 39 | + 'invitation_code': '', |
| 40 | + 'token': token, |
| 41 | + 'smsToken': '', |
| 42 | + 'luoToken': '', |
| 43 | + 'confirmPassword': '', |
| 44 | + 'loginType': '' |
| 45 | + } |
| 46 | + res = self.api('token', data, 'jwt') |
| 47 | + self.auth = res['token'] |
| 48 | + self.headers.update({'authorization': f'Bearer {self.auth}'}) |
| 49 | + self.get_task_data() |
| 50 | + |
| 51 | + def get_task_data(self): |
| 52 | + res = self.api('getTaskData', {}) |
| 53 | + print(res) |
| 54 | + for k, v in res['task'].items(): |
| 55 | + if v['finish'] != v['times']: |
| 56 | + print(k, v) |
| 57 | + |
| 58 | + if v['name'] == '签到': |
| 59 | + pass |
| 60 | + |
| 61 | + if v['name'] == '评论': |
| 62 | + print(v['url']) |
| 63 | + self.comment_submit(v['url'].split('/')[-2]) |
| 64 | + |
| 65 | + if v['name'] == '关注某人': |
| 66 | + for i in range(v['times'] - v['finish']): |
| 67 | + self.author_follow() |
| 68 | + time.sleep(2) |
| 69 | + else: |
| 70 | + print(v['name'], '已完成') |
| 71 | + |
| 72 | + def author_follow(self): |
| 73 | + res = requests.get('https://www.fakerengine.com/?s=&type=user', headers=self.headers).text |
| 74 | + html = etree.HTML(res) |
| 75 | + user_ids = [] |
| 76 | + user_links = html.xpath("//div[@class='user-s-cover']/a/@href") |
| 77 | + for user_link in user_links: |
| 78 | + user_id = user_link.split('/')[-1] |
| 79 | + user_ids.append(user_id) |
| 80 | + data = {} |
| 81 | + for i in range(len(user_ids)): |
| 82 | + data.update({f'ids[{i}]': user_ids[i]}) |
| 83 | + res = self.api('checkFollowByids', data) |
| 84 | + for k, v in res.items(): |
| 85 | + if not v: |
| 86 | + self.api('AuthorFollow', {'user_id': k}) |
| 87 | + break |
| 88 | + |
| 89 | + def comment_submit(self, comment_post_id: int): |
| 90 | + res = self.api('commentSubmit', { |
| 91 | + 'comment_post_ID': comment_post_id, |
| 92 | + 'author': self.username, |
| 93 | + 'comment': '板凳', |
| 94 | + 'comment_parent': '0', |
| 95 | + 'img[imgUrl]': '', |
| 96 | + 'img[imgId]': '' |
| 97 | + }) |
| 98 | + print(res) |
| 99 | + |
| 100 | + |
| 101 | +if __name__ == '__main__': |
| 102 | + faker = Faker('用户名', '密码') |
| 103 | + faker.login() |
0 commit comments