网络爬虫作业

import requests
import json
try:
    
   r=requests.get('https://edu.cnblogs.com/Homework/GetAnswers?homeworkId=2420&_=1543716986749')
   r.raise_for_status()
   r.text
except:
    print('网页无法打开')
json_data=json.loads(r.text)['data']
for a in json_data:
    date+=str(a['StudentNo'])+','+a['RealName']+','+a['DateAdded'].replace('T',' ')+','+a['Title']+','+a['Url']+'\n'
with open('E:\hwlist.csv','w')as f:
    f.write(date)

 

posted @ 2018-12-04 18:46  stxuan  阅读(117)  评论(0)    收藏  举报