用python中requests库爬取猫眼电影信息并保存到csv文件中
猫眼专业版
爬取界面
效果预览
代码
import requests
import jsonurl1='https://piaofang.maoyan.com/dashboard-ajax?orderType=0&uuid=1938bd58ddac8-02c2bbe3b009ed-4c657b58-144000-1938bd58ddac8&timeStamp=1733295218252&User-Agent=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEzMS4wLjAuMCBTYWZhcmkvNTM3LjM2IEVkZy8xMzEuMC4wLjA%3D&index=77&channelId=40009&sVersion=2&signKey=dc78cae9f347e2832485a666a8531266'headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0'
}response = requests.get(url=url1, headers=headers)
response.encoding = 'utf-8'
info = response.text# 将上述爬取到的json格式的字符串转成python中的字典进行数据分析
info=json.loads(info)movies=info["movieList"]["data"]["list"]
f=open('movie.csv',mode='a',encoding='utf-8')
for i in movies:movie_id = i['movieInfo']['movieId']movie_name=i['movieInfo']["movieName"]movie_Release= i['movieInfo']['releaseInfo']movie_box = i['boxSplitUnit']['num']str=f"{movie_id},{movie_name},{movie_Release}"f.write(f"{str}\n")f.flush()
f.close()