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