Python网络爬虫作业

代码如下:

import requests
import json
import time
try:
    a = requests.get('https://edu.cnblogs.com/Homework/GetAnswers?homeworkId=2420&_=1543758681318')
except:       
    print('Error')
def cd():
    b = json.loads(a.text)['data']
    e = ''
    for i in b:
        c = (str(i['StudentNo']) + ',' + str(i['RealName']) + ',' + str(i['Title']) + ',' + str(i['DateAdded'].replace('T',' ')) + ',' + str(i['BlogUrl'])).replace('None','助教')
        e = e + c + '\n'
        print(e)
        with open('C:\\Users\\刘进宝\\Desktop\\hwlist.csv','w') as f:
            f.write(e)
while True:
    cd()
    time.sleep(3600)

 

 

 

部分运行结果如下(单元格格式更改过):

 

posted @ 2018-12-03 11:02  刘进宝  阅读(245)  评论(0编辑  收藏  举报