您的位置:首页 > 游戏 > 手游 > 天津做个网站需要多少钱_站内推广的几种方式_佛山网站定制_太原seo推广外包

天津做个网站需要多少钱_站内推广的几种方式_佛山网站定制_太原seo推广外包

2025/2/24 13:05:43 来源:https://blog.csdn.net/2303_79350799/article/details/145431885  浏览:    关键词:天津做个网站需要多少钱_站内推广的几种方式_佛山网站定制_太原seo推广外包
天津做个网站需要多少钱_站内推广的几种方式_佛山网站定制_太原seo推广外包

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

步骤:

(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()

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com