Python爬取ajax動態載入內容
阿新 • • 發佈:2018-12-09
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()