基础13·豆瓣热门电影top250抓取(csv文件的使用)


import requests, json, time

num = [0, 51, 101, 151, 201, ]
for i in num:
    url = "https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&page_limit=50&page_start={i}".format(i=i)
    r = requests.get(url)  # 请求
    ret = r.text
    result = json.loads(ret)
    the_list = result['subjects']
    for content in the_list:
        title = content['title']
        rate = content['rate']
        url = content['url']

        with open("C://Users/Administrator/Desktop/" + '豆瓣爬取数据.csv', 'a')as f:
            f.write('{},{},{}\n'.format(title, rate, url))
            time.sleep(1)

结果展示:

基础13·豆瓣热门电影top250抓取(csv文件的使用)_第1张图片

你可能感兴趣的:(基础爬虫及进阶)