Python爬取微博(APP)榜单爬虫及数据可视化,整理出Python逆向系列学习进阶视频

f = open(‘1.csv’,‘w+’,encoding=‘utf-8’,newline=‘’)

writer = csv.writer(f)

writer.writerow([‘user_id’,‘user_location’,‘user_gender’,‘user_follower’,‘text’,‘created_time’,‘reposts_count’,‘comments_count’,‘attitudes_count’])

def get_info(url):

res = requests.get(url,headers=headers)

print(url)

datas = re.findall(‘“mblog”.*?),“weibo_position”’,res.text,re.S)

for data in datas:

json_data = json.loads(data+‘}’)

user_id = json_data[‘user’][‘name’]

user_location = json_data[‘user’][‘location’]

user_gender = json_data[‘user’][‘gender’]

user_follower = json_data[‘user’][‘followers_count’]

text = json_data[‘text’]

created_time = json_data[‘created_at’]

reposts_count = json_data[‘reposts_count’]

comments_count = json_data[‘comments_count’]

attitudes_count = json_data[‘attitudes

你可能感兴趣的:(2024年程序员学习,python,爬虫,信息可视化)