python 科幻片采集

豆瓣科幻片1000条记录

import requests
import xlwt
import json
import time

def start():
    wb = xlwt.Workbook()
    ws = wb.add_sheet('douban')
    ws.write(0, 0, "影片名称")
    ws.write(0, 1, "评分")
    row = 1
    for i in range(0,1000,20):
        url= "https://movie.douban.com/j/new_search_subjects?sort=U&range=0,10&tags=&start="+str(i)+"&genres=%E7%A7%91%E5%B9%BB"
        headers ={
            'Cookie': 'bid=HNf-ab2-lJI; gr_user_id=031667b7-5f8a-4ede-b695-e52d9181fe11; __gads=ID=60db1851df53b133:T=1583253085:S=ALNI_MbBwCgmPG1hMoA4-Z0HSw_zcT0a0A; _vwo_uuid_v2=DD32BB6F8D421706DCD1CDE1061FB7A45|ef7ec70304dd2cf132f1c42b3f0610e7; viewed="1200840_27077140_26943161_25779298"; ll="118165"; __yadk_uid=5OpXTOy4NkvMrHZo7Rq6P8VuWvCSmoEe; ct=y; ap_v=0,6.0; push_doumail_num=0; push_noty_num=0; _pk_ref.100001.4cf6=%5B%22%22%2C%22%22%2C1583508410%2C%22https%3A%2F%2Fwww.pypypy.cn%2F%22%5D; _pk_ses.100001.4cf6=*; dbcl2="131182631:x7xeSw+G5a8"; ck=9iia; _pk_id.100001.4cf6=17997f85dc72b3e8.1583492846.4.1583508446.1583505298.',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 OPR/66.0.3515.115'}
        res =requests.get(url,headers = headers)
        j = json.loads(res.text)
        lens= len(j['data'])
        for ind in range(0,lens):
            title = j['data'][ind]['title']
            rate = j['data'][ind]['rate']
            print(title+"---"+rate)
            ws.write(row, 0, title)
            ws.write(row, 1, rate)
            row = row + 1
        time.sleep(8)
    wb.save('douban.xls')
start()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值