Created
May 24, 2022 12:11
-
-
Save runningzyp/205e5faecdbaf64627fe0b86b4f1aaca to your computer and use it in GitHub Desktop.
取关微博最近关注的博主
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import json | |
| # from tqdm import tqdm | |
| filter_choice = { | |
| "1": "7天内新增", | |
| "2": "30天内新增", | |
| "3": "半年内新增", | |
| } | |
| COOKIE = '' # 替换为自己的 | |
| HEADERS = { | |
| 'authority': 'weibo.com', | |
| 'pragma': 'no-cache', | |
| 'cache-control': 'no-cache', | |
| 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"', | |
| 'x-xsrf-token': 'cQ1VlVYbrh-U8KbKHLoGryo1', | |
| 'traceparent': '00-4f4e0e0ba8eec019109ef693b856752f-af7a3265ceb43080-00', | |
| 'sec-ch-ua-mobile': '?0', | |
| 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36', | |
| 'accept': 'application/json, text/plain, */*', | |
| 'x-requested-with': 'XMLHttpRequest', | |
| 'sec-ch-ua-platform': '"macOS"', | |
| 'sec-fetch-site': 'same-origin', | |
| 'sec-fetch-mode': 'cors', | |
| 'sec-fetch-dest': 'empty', | |
| 'referer': 'https://weibo.com/u/page/follow/5705735415', | |
| 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7', | |
| 'cookie': COOKIE | |
| } | |
| def unfollow(): | |
| filter_choice = "2" | |
| url = f"https://weibo.com/ajax/profile/followContent?sortType=filter&filter_code={filter_choice}&page=3&page_size=" | |
| response = requests.request("GET", url, headers=HEADERS) | |
| if response.status_code == 200: | |
| result = response.json() | |
| total = result['data']['total_number'] | |
| user_ids = [x['idstr'] for x in result['data']['follows']['users']] | |
| user_names = [x['name'] for x in result['data']['follows']['users']] | |
| print("关注列表如下:") | |
| for name in user_names: | |
| print("\t\t", end="") | |
| print(name) | |
| ret = input("是否取消关注? 回车继续,q退出:") | |
| if ret == 'q': | |
| return | |
| url = "https://weibo.com/ajax/profile/destroyBatch" | |
| payload = json.dumps({"uids": (",").join(user_ids)}) | |
| response = requests.request("POST", url, headers=HEADERS, data=payload) | |
| if response.json()['data']['result']: | |
| print("取消关注成功:还剩余{}个!\n".format(total)) | |
| return total | |
| if __name__ == '__main__': | |
| while unfollow(): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment