zoukankan      html  css  js  c++  java
  • Python3爬取ACM近期比赛数据并写入Excel文档

    这个爬虫是今年暑假时学完小甲鱼的Python视频后写的。关于Python3的爬虫教程不多,下面只是使用了一些简单的用法。

    程序使用了”xlwt”包,用于创建Excel文档并写入数据,安装很简单:pip install xlwt

    关于ACM近期比赛,下面的链接种给出了一个json格式的源数据。我们可以用Python的urllib下载下来,然后解析这个json即可。

    http://contests.acmicpc.info/contests.json

    import xlwt, json, urllib.request
    
    def getDate():
        page = urllib.request.urlopen("http://contests.acmicpc.info/contests.json")
        return page.read().decode()
    
    def getJson(s):
        j = json.loads(s)
        return j
    
    def writeExcel(header, v):
        wb = xlwt.Workbook()
        ws = wb.add_sheet('Sheet1')
        for c in range(len(header)):
            ws.write(0, c, header[c])
            for r in range(len(v)):
                ws.write(r+1, c, v[r][header[c]])
        wb.save('Recent contests.xls')
    
    header = ['oj', 'name', 'link', 'start_time', 'week', 'access']
    writeExcel(header, getJson(getDate()))
  • 相关阅读:
    GDB 用法
    C编程规范
    PHP面向对象
    cron定时任务
    Apatche配置基础
    正则表达式笔记
    PHP在windows下命令行方式
    面试题
    struts与ajax的关系
    ORACLE DUAL表详解
  • 原文地址:https://www.cnblogs.com/kunsoft/p/13675298.html
Copyright © 2011-2022 走看看