HDUOJ题目HTML的爬取

HDUOJ题目HTML的爬取

封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可。

其实没什么难度,先爬下来一个题目的html,然后正则匹配一波塞个标签上去就好了。

下图运行效果:

下面是爬取下的HTML运行效果:

源码:

import re
import requests
from requests.exceptions import RequestException

url = "http://acm.hdu.edu.cn/showproblem.php?pid=" + input("HDU题号:")
headers = {
    'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15"}


def get_one_page(url, headers):
    try:
        response = requests.get(url, headers=headers)
        if response.status_code == 200:
            response.encoding = 'utf-8'
            return response.text
        return None
    except RequestException:
        return None


html = get_one_page(url, headers=headers)
tmp=re.findall('<tr><td align=center>(.*?)</tr>',html,re.S)[0]
ans=re.findall('<h1 (.*?)<br><div class=panel_title(.*)',tmp,re.S)[0]
print('<center><h1 '+ans[0]+'</center><br><div class=panel_title'+ans[1])
ask=input('按任意键退出')
View Code

求求你们放过我的博客吧,转载要注明出处呀。。

转载于:https://www.cnblogs.com/Rhythm-/p/9376764.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值