requests用法之爬取豆瓣排行

爬取 豆瓣排行

import requests

url = "https://movie.douban.com/j/chart/top_list?type_name=科幻&type=17&interval_id=100:90&action="
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"}
proxies = {"http":"http://163.204.241.255:9999","https":"https://163.125.67.224:9797"} #代理ip

response = requests.get(url=url,proxies=proxies,headers=headers)
result = response.json()
# print(result)
for i in result:  #提取数据
    print(i)
    rating = i["rating"]  #评分
    print(rating)
    score = i["score"]  #评分
    cover_url = i["cover_url"]  #图片链接
    types = i["types"]  #类型
    title = i["title"]  #标题
    release_date = i["release_date"]  #上映日期
    vote_count = i["vote_count"]  #评价人数
    actors = i["actors"]  #演员
    info = "电影名称:{},评分:{},图片:{},上映日期:{},评价人数:{}".format(title,score,cover_url,release_date,vote_count)
    print(info)
    with open("douban.txt", "a", encoding="utf-8")as f:  #写入txt文件
        f.write(info+"\n")

猜你喜欢

转载自blog.csdn.net/qq_40576301/article/details/99885157