使用python爬取javascript题库 每日一题

来源博客:【Harryの心阁

题目开源

来自:前端3+1,每天更新一题 有html,css,javascript,软技能

python代码

#  -*-coding:utf8 -*-
import os, requests, json


# 获取题目到title.json文件中

def getData():
    res = requests.get('http://api.h-camel.com/api?mod=interview&ctr=issues&act=history').json()
    with open('title.json', 'w+', encoding='UTF-8') as f:
        f.write(json.dumps(res, ensure_ascii=False))
        f.close()


def postTitle():
    with open('title.json', encoding='UTF-8') as f:
        res = json.loads(f.read())['result'][f'{dayN}_']
        if len(res) == 4:
            backTitle(res, 'html', 'css', 'js', 'skill')
        else:
            backTitle(res, 'html', 'css', 'js')


def backTitle(dataList, *args):
    for index, item in enumerate(args):
        title = f'第{dayN}天问题:' + dataList[item]['title']
        if dayN <= 11:
            print(f'{title}\n链接地址:http://www.h-camel.com/show/{(int(dayN) - 1) * len(args) + index + 1}.html')
        else:
            print(f'{title}\n链接地址:http://www.h-camel.com/show/{33 + (int(dayN) - 12) * len(args) + index + 1}.html')


if __name__ == "__main__":
    # 题目文件
    folder = os.path.exists('title.json')
    dayN = 10  # 定义全局变量 天数
    if folder == False:
        getData()
    postTitle()  # 获取题目,改变参数 表示天数

结果演示

10天问题:viewport常见设置都有哪些?
链接地址:http://www.h-camel.com/show/28.html
第10天问题:对比下px、em、rem有什么不同?
链接地址:http://www.h-camel.com/show/29.html
第10天问题:简要描述下什么是回调函数并写一个例子出来
链接地址:http://www.h-camel.com/show/30.html

公众号:今日在学

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Harry-iu

顺手给小编加个鸡腿????

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值