selenium记录Spiderbuf例题C01

server/2025/2/8 4:07:02/

防止自己遗忘,故作此为记录。

步骤:

(1)进入例题,找到需要点击的元素。

可得button xpath

click_xpath: str = r'//li/a[@title="mnist"]'
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, click_xpath)))
res = driver.find_element(By.XPATH, click_xpath)

注意,此时点击res的attribute是完整url。(卡顿在此步,以为url还需要拼接)

之后发现:

 可得final_xpath:

final_xpath: str = r"//tbody/tr/td[2]"
WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, final_xpath)))
res: list = driver.find_elements(By.XPATH, final_xpath)

最后计算:

res: list[float] = [eval(e.text) for e in res]
s: Decimal = Decimal("0.0")for each in res:s += Decimal(each)
s /= len(res)print(f"{s=}")
s2=Decimal('3.766666666666666666666666667')
#四舍五入为3.77

完整代码:

# -*- coding: utf-8 -*-
# -*- file: C01.py  -*-from decimal import Decimal
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeServicefirst_url: str = r"https://www.spiderbuf.cn/playground/c01"service = ChromeService(r"C01\chromedriver-win64\chromedriver.exe")
options = ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_argument("--disable-blink-features=AutomationControlled")driver = Chrome(options=options, service=service)driver.get(first_url)click_xpath: str = r'//li/a[@title="mnist"]'
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, click_xpath)))
res = driver.find_element(By.XPATH, click_xpath)
driver.implicitly_wait(3)driver.get(res.get_attribute("href"))#WebDriverWait(driver, 10).until(lambda driver: driver.current_url != first_url)
final_xpath: str = r"//tbody/tr/td[2]"WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, final_xpath)))
res: list = driver.find_elements(By.XPATH, final_xpath)res = [eval(e.text) for e in res]
length: int = len(res)s1: float = sum(res) / lengths2: Decimal = Decimal("0.0")for each in res:s2 += Decimal(each)s2 /= lengthprint(f"{s1=}", f"{s2=}")driver.close()

 


http://www.ppmy.cn/server/165844.html

相关文章

洛谷 P8724 [蓝桥杯 2020 省 AB3] 限高杆

洛谷题目传送门 题目描述 某市有 n 个路口,有 m 段道路连接这些路口,组成了该市的公路系统。其中一段道路两端一定连接两个不同的路口。道路中间不会穿过路口。 由于各种原因,在一部分道路的中间设置了一些限高杆,有限高杆的路…

介绍使用 WGAN(Wasserstein GAN)网络对天然和爆破的地震波形图进行分类的实现步骤

以下将为你详细介绍使用 WGAN(Wasserstein GAN)网络对天然和爆破的地震波形图进行分类的实现步骤,包含代码实现和项目结题报告的大纲。 代码实现 1. 环境准备 确保你已经安装了必要的库,如 torch、torchvision、numpy、matplot…

C语言——深入理解指针(1)

深入理解指针 内存和地址内存究竟该如何理解编址呢? 指针变量和地址取地址操作符(&)指针变量和解引用操作符(*)指针变量如何拆解指针类型解引用操作符 指针变量的大小 指针变量类型的意义指针的解引用指针-整数voi…

DeepSeek:全栈开发者视角下的AI革命者

目录​​​​​​​ DeepSeek:全栈开发者视角下的AI革命者 写在前面 一、DeepSeek的诞生与定位 二、DeepSeek技术架构的颠覆性突破 1、解构算力霸权:从MoE架构到内存革命 2、多模态扩展的技术纵深 3、算法范式的升维重构 4、重构AI竞争规则 三、…

pytorch基于FastText实现词嵌入

FastText 是 Facebook AI Research 提出的 改进版 Word2Vec,可以: ✅ 利用 n-grams 处理未登录词 比 Word2Vec 更快、更准确 适用于中文等形态丰富的语言 完整的 PyTorch FastText 代码(基于中文语料),包含&#xff1…

windows phpstudy python cgi配置

修改apache配置文件:httpd.conf 搜索’Define SRVROOT’, 查看cgi根目录,python脚本需要放在该 Define SRVROOT "D:/Program/phpstudy_pro/Extensions/Apache2.4.39解决中文乱码 文件最后添加AddDefaultCharset gbk 重启apache python脚本: #!py…

云上考场微信小程序的设计与实现(LW+源码+讲解)

专注于大学生项目实战开发,讲解,毕业答疑辅导,欢迎高校老师/同行前辈交流合作✌。 技术范围:SpringBoot、Vue、SSM、HLMT、小程序、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、安卓app、大数据、物联网、机器学习等设计与开发。 主要内容:…

网络安全--边界安全

现在人们生活依赖互联网程度越来越高,网络安全也逐步进入人们日常视野,信用卡信息泄漏、开房记录被查询、商业机密泄漏等等;无不牵动着一个人、一个公司、甚至一个国家的神经。随着技术的发展,网络边界变得也越来越复杂&#xff0…