Python爬取ajax动态加载内容

import requests
import json
import csv
url= "https://movie.douban.com/j/chart/top_list?"

params={
"type":17,
"interval_id"   :"100:90",
"action":"",    
"start":0,
"limit":100}

headers = {"User-Agent":"Mozilla5.0/"}

res = requests.get(url,params=params,headers=headers)
res.encoding = "utf-8"
html = res.text
#print(html)
L = json.loads(html)

with open("豆瓣100.csv","a",newline="") as f:
    for fielm in L:
        #    print(fielm)
        score = fielm["rating"][0]  
        name = fielm["title"]
        writer = csv.writer(f)
        writer.writerow([name,score])
f.close()


你可能感兴趣的:(爬虫)