|
| 1 | +# coding=utf-8 |
| 2 | +import requests |
| 3 | +import json |
| 4 | +import time |
| 5 | +import random |
| 6 | + |
| 7 | + |
| 8 | +class TiMo(): |
| 9 | + def __init__(self): |
| 10 | + self.baseUrl = "https://api.amemv.com/aweme/v1/aweme/post/?iid=35150003561&device_id=48526500596&os_api=18&app_name=aweme&channel=App%20Store&idfa=D420CB58-25ED-441A-B1E5-FDD8442D0A48&device_platform=iphone&build_number=18504&vid=BDF5B471-35B1-41F0-A6A5-3C85D48DA550&openudid=de110aa76e414c0163cc220e94b9b25c88ede2c1&device_type=iPhone9,2&app_version=1.8.5&version_code=1.8.5&os_version=11.2.6&screen_width=1242&aid=1128&ac=WIFI&count=21&max_cursor=0&min_cursor=0&user_id=58958068057&mas=005ccbf596dd5116e932383c4e6e73aede7fa5761951141f7b6ebe&as=a1b5e5712aaf7b023e8205&ts=1528713978" |
| 11 | + self.video_headers = { |
| 12 | + # ':method': 'GET', |
| 13 | + # ':scheme': 'https', |
| 14 | + # ':path': '/aweme/v1/aweme/post/?iid=35150003561&device_id=48526500596&os_api=18&app_name=aweme&channel=App%20Store&idfa=D420CB58-25ED-441A-B1E5-FDD8442D0A48&device_platform=iphone&build_number=18504&vid=BDF5B471-35B1-41F0-A6A5-3C85D48DA550&openudid=de110aa76e414c0163cc220e94b9b25c88ede2c1&device_type=iPhone9,2&app_version=1.8.5&version_code=1.8.5&os_version=11.2.6&screen_width=1242&aid=1128&ac=WIFI&count=21&max_cursor=0&min_cursor=0&user_id=58958068057&mas=005ccbf596dd5116e932383c4e6e73aede7fa5761951141f7b6ebe&as=a1b5e5712aaf7b023e8205&ts=1528713978', |
| 15 | + # ':authority': 'api.amemv.com', |
| 16 | + 'cookie': 'install_id=35150003561; odin_tt=a004eee5fc56a9e4dc6376f1afccd5e9d8648417ea2e5c8ae45f0cbd8907b0bc618275bc4ba8d98fb9100a19c223a65e; sessionid=8877a21fc511c3805d91de1b5c89498e; sid_guard=8877a21fc511c3805d91de1b5c89498e%7C1528619671%7C2592000%7CTue%2C+10-Jul-2018+08%3A34%3A31+GMT; sid_tt=8877a21fc511c3805d91de1b5c89498e; ttreq=1$2a3dd8106fc952d9f8b84cbeae80d53e1159f929; uid_tt=9633b543f1cba4c3cb7bf185158eb579', |
| 17 | + 'accept': '*/*', |
| 18 | + 'user-agent': 'Aweme/1.8.5 (iPhone; iOS 11.2.6; Scale/3.00)', |
| 19 | + 'accept-language': 'zh-Hans-CN;q=1', |
| 20 | + 'accept-encoding': 'br, gzip, deflate' |
| 21 | + } |
| 22 | + self.comment_headers = { |
| 23 | + 'cookie': 'install_id=35150003561; odin_tt=a004eee5fc56a9e4dc6376f1afccd5e9d8648417ea2e5c8ae45f0cbd8907b0bc618275bc4ba8d98fb9100a19c223a65e; sessionid=8877a21fc511c3805d91de1b5c89498e; sid_guard=8877a21fc511c3805d91de1b5c89498e%7C1528619671%7C2592000%7CTue%2C+10-Jul-2018+08%3A34%3A31+GMT; sid_tt=8877a21fc511c3805d91de1b5c89498e; ttreq=1$2a3dd8106fc952d9f8b84cbeae80d53e1159f929; uid_tt=9633b543f1cba4c3cb7bf185158eb579', |
| 24 | + 'accept': '*/*', |
| 25 | + 'user-agent': 'Aweme/1.8.5 (iPhone; iOS 11.2.6; Scale/3.00)', |
| 26 | + 'accept-language': 'zh-Hans-CN;q=1', |
| 27 | + 'accept-encoding': 'br, gzip, deflate' |
| 28 | + } |
| 29 | + self.cursor = 0 |
| 30 | + self.unique_id_modify_time = 1528719888 |
| 31 | + self._as = 'a155c601d0f1ab2a0e0086' |
| 32 | + self.mas = '0099709b51b018cc14ce29bf6f9f4a3f7b95f5372bb18abf2aaf31' |
| 33 | + self.base_str = 'abcdefghigklmnopqrstuvwxyz0123456789' |
| 34 | + |
| 35 | + def request_timo_video(self): |
| 36 | + # 提莫名下视频 |
| 37 | + response = requests.get(self.baseUrl, headers=self.video_headers) |
| 38 | + if(response.status_code == 200): |
| 39 | + self.__parse_data(response.text) |
| 40 | + |
| 41 | + def __parse_data(self, text): |
| 42 | + result = json.loads(text) |
| 43 | + datas = result['aweme_list'] |
| 44 | + for data in datas: |
| 45 | + download_url = data['video']['download_addr']['url_list'] |
| 46 | + duration = data['video']['duration']/(1000*1000) |
| 47 | + duration = '%.2fM' % duration |
| 48 | + play_url = data['video']['play_addr']['url_list'] |
| 49 | + nick_name = data['author']['nickname'] |
| 50 | + music_title = data['music']['title'] |
| 51 | + share_title = data['share_info']['share_title'] |
| 52 | + |
| 53 | + print("作者:%s 标题:%s 视频下载地址:%s 时长:%s 播放地址:%s 音乐:%s " % ( |
| 54 | + nick_name, share_title, download_url, duration, play_url, music_title)) |
| 55 | + print("************************************************************") |
| 56 | + |
| 57 | + def request_timo_comment(self): |
| 58 | + # 提莫名下评论 |
| 59 | + url = "https://api.amemv.com/aweme/v1/comment/list/?iid=35150003561&device_id=48526500596&os_api=18&app_name=aweme&channel=App%20Store&idfa=D420CB58-25ED-441A-B1E5-FDD8442D0A48&device_platform=iphone&build_number=18504&vid=BDF5B471-35B1-41F0-A6A5-3C85D48DA550&openudid=de110aa76e414c0163cc220e94b9b25c88ede2c1&device_type=iPhone9,2&app_version=1.8.5&version_code=1.8.5&os_version=11.2.6&screen_width=1242&aid=1128&ac=WIFI&aweme_id=6564996818420108547&comment_style=2&count=20&cursor={}&digged_cid=&mas={}&as={}&ts={}" |
| 60 | + response = requests.get(url.format( |
| 61 | + self.cursor, self.mas, self._as, self.unique_id_modify_time), headers=self.comment_headers) |
| 62 | + if response.status_code == 200: |
| 63 | + self.__request_to_get_comment(response.text) |
| 64 | + |
| 65 | + def __request_to_get_comment(self, text): |
| 66 | + result = json.loads(text) |
| 67 | + |
| 68 | + try: |
| 69 | + if 1 == result['has_more']: |
| 70 | + for data in result['comments']: |
| 71 | + comment = data['text'] |
| 72 | + digg_count = data['digg_count'] |
| 73 | + print("共有{}赞 {}".format(digg_count, comment)) |
| 74 | + |
| 75 | + self.cursor = result['cursor'] |
| 76 | + self.unique_id_modify_time = result['comments'][-1]['user']['unique_id_modify_time'] |
| 77 | + |
| 78 | + # 以下采用随机替换mas 和 as |
| 79 | + l = list(self.mas) |
| 80 | + l[random.randint(0, len(l)-1)] = random.choice(self.base_str) |
| 81 | + self.mas = "".join(l) |
| 82 | + m = list(self._as) |
| 83 | + m[random.randint(0, len(m)-1)] = random.choice(self.base_str) |
| 84 | + self._as = "".join(m) |
| 85 | + |
| 86 | + time.sleep(2) |
| 87 | + self.request_timo_comment() |
| 88 | + |
| 89 | + else: |
| 90 | + print("无数据") |
| 91 | + except Exception as e: |
| 92 | + print(result) |
| 93 | + print(str(e)) |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == '__main__': |
| 97 | + timo = TiMo() |
| 98 | + # 爬取提莫名下所有的短视频 |
| 99 | + # timo.request_timo_video() |
| 100 | + # 爬取提模第一个视频的评论及评论的点赞 |
| 101 | + timo.request_timo_comment() |
0 commit comments