豆瓣科幻片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()