| 19 | |
| 20 | |
| 21 | def get_infos(): |
| 22 | url = "https://abs.twimg.com/responsive-web/client-web/main.8644ab25.js" |
| 23 | response = requests.get(url, proxies=proxies, verify=False) |
| 24 | authorization = "Bearer " + re.search("(AAAAA.*?)\"", response.text).group(1) |
| 25 | user_tweets = re.search('queryId:\"(.{22})\",operationName:\"UserTweets\",', response.text).group(1) |
| 26 | user_by_screen_name = re.search('queryId:\"(.{22})\",operationName:\"UserByScreenName\",', response.text).group(1) |
| 27 | gt_headers = { |
| 28 | 'authority': 'api.twitter.com', |
| 29 | 'content-length': '0', |
| 30 | 'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"', |
| 31 | 'x-twitter-client-language': 'zh-cn', |
| 32 | 'sec-ch-ua-mobile': '?0', |
| 33 | 'authorization': authorization, |
| 34 | 'content-type': 'application/x-www-form-urlencoded', |
| 35 | 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' |
| 36 | 'Chrome/97.0.4692.99 Safari/537.36', |
| 37 | 'x-twitter-active-user': 'yes', |
| 38 | 'sec-ch-ua-platform': '"Windows"', |
| 39 | 'accept': '*/*', |
| 40 | 'origin': 'https://twitter.com', |
| 41 | 'sec-fetch-site': 'same-site', |
| 42 | 'sec-fetch-mode': 'cors', |
| 43 | 'sec-fetch-dest': 'empty', |
| 44 | 'referer': 'https://twitter.com/', |
| 45 | 'accept-language': 'zh-CN,zh;q=0.9', |
| 46 | } |
| 47 | logger.debug('开始获取guest_token...') |
| 48 | response_gt = requests.post('https://api.twitter.com/1.1/guest/activate.json', proxies=proxies, headers=gt_headers, |
| 49 | verify=False) |
| 50 | return dict( |
| 51 | guest_token=response_gt.json()['guest_token'], |
| 52 | authorization=authorization, |
| 53 | user_tweets=user_tweets, |
| 54 | user_by_screen_name=user_by_screen_name |
| 55 | ) |
| 56 | |
| 57 | |
| 58 | infos = get_infos() |