| 39 | |
| 40 | |
| 41 | def get_data(city_code, city_s): |
| 42 | wb = Workbook() |
| 43 | ws = wb.active |
| 44 | ws.append(['用户名', '粉丝数', '作品数', '平均点赞', '平均转发', '平均评论', '平均收藏', '账号类型', '友望指数']) |
| 45 | url = f'https://api.youwant.cn/v1/blogger/search?pageIndex=1&pageSize=10&level1CategoryId=12&level2CategoryId=0&SortType=1&cityId={city_code}&type=-1&_=1678261008747' |
| 46 | response = requests.get(url, headers=headers, cookies=cookies).json() |
| 47 | # print(response) |
| 48 | for city in city_s: |
| 49 | city_list = str(response['Data']['ItemList']) |
| 50 | # print(city_list) |
| 51 | if str(city) in city_list: |
| 52 | print(city) |
| 53 | item_list = response['Data']['ItemList'] |
| 54 | for item in item_list: |
| 55 | # 用户名 |
| 56 | user_name = item['NickName'] |
| 57 | # 粉丝数 |
| 58 | fans_count = item['FansCountDesc'] |
| 59 | # 作品数 |
| 60 | works_count = item['FeedsCountDesc'] |
| 61 | # 平均点赞 |
| 62 | avg_like = item['AvgLikeCountDesc'] |
| 63 | # 平均转发 |
| 64 | avg_forward = item['AvgForwardCountDesc'] |
| 65 | # 平均评论 |
| 66 | avg_comment = item['AvgCommentCountDesc'] |
| 67 | # 平均收藏 |
| 68 | avg_collect = item['AvgFavCountDesc'] |
| 69 | # 账号类型 |
| 70 | account_type = item['CategoryName'] |
| 71 | # 友望指数 |
| 72 | friend_index = item['GuaZhiShuDesc'] |
| 73 | ws.append([user_name, fans_count, works_count, avg_like, avg_forward, avg_comment, avg_collect, |
| 74 | account_type, friend_index]) |
| 75 | print(user_name, fans_count, works_count, avg_like, avg_forward, avg_comment, avg_collect, account_type, |
| 76 | friend_index) |
| 77 | wb.save(rf'./data/{city}.xlsx') |
| 78 | |
| 79 | |
| 80 | if __name__ == '__main__': |