跳到正文

科技·工程

当你写了个 bug 却刚好能够运行(2)

_Spectator_约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年7月24日
篇幅
约 3 分钟

版本

  1. v1当前

nh.51goc.com 评测结果爬虫

Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
import time, re

options = Options()
options.add_argument("--headless=new")
options.add_argument("--disable-gpu")
options.add_argument('--log-level=3')
driver = webdriver.Edge(options = options)
url = "https://nh.51goc.com/problem/submissions/code/"
name = "黄海韬"
username = "sm黄海韬"
password = "sm2025"
while True:
    try:
        rid = int(input('start from: '))
    except ValueError: continue
    driver.get("https://nh.51goc.com/login")
    time.sleep(1)
    inputs = driver.find_elements(By.TAG_NAME, 'input')
    if inputs:
        inputs[0].send_keys(username)
        inputs[1].send_keys(password)
        driver.find_element(By.TAG_NAME, 'button').click()
        time.sleep(1)
    while True:
        rid = rid + 1
        driver.get(url = url + str(rid))
        if driver.title == "错误提示!": continue
        HTML = driver.page_source
        if not re.findall(f"提交人:{name}", HTML): break
        print(url + str(rid))
        print(driver.find_element(By.XPATH, "/html/body/div/div/div/span[1]").text)
        print(driver.find_element(By.XPATH, "/html/body/div/div/div/span[2]/label[2]").text[5:])
        print()
    print('end at:', rid - 1)
driver.close()

upd on 2025/9/4

原文