不单击所有选项卡并且不循环一次问题

2024-01-11

I am trying to click the tabs on the webpage as seen below. Unfortunately, it only seems to click some of the tabs despite correct correct xpath in inspect Chrome. I can only assume it’s not clicking all the tabs because the full xpath is not being used. enter image description here

然而.. 我尝试过更改xpath:

//div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"] To:

//div[@class='KambiBC-event-groups-list']//div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"] FOR:

clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//div[@class="KambiBC-collapsible-container KambiBC-mod-event-group-container"])[%s]' % str(index + 1))))    

但问题仍然存在。 我也尝试过使用CSS:

#KambiBC-contentWrapper__bottom > div > div > div > div > div.KambiBC-quick-browse-container.KambiBC-quick-browse-container--list-only-mode > div.KambiBC-quick-browse__list.KambiBC-delay-scroll--disabled > div > div.KambiBC-time-ordered-list-container > div.KambiBC-time-ordered-list-content > div > div > div.KambiBC-collapsible-container.KambiBC-mod-event-group-container > header

然而这一直给我错误...... 为了:

clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'("#KambiBC-contentWrapper__bottom > div > div > div > div > div.KambiBC-quick-browse-container.KambiBC-quick-browse-container--list-only-mode > div.KambiBC-quick-browse__list.KambiBC-delay-scroll > div > div.KambiBC-time-ordered-list-container > div.KambiBC-time-ordered-list-content > div > div > div > header")[%s]' % str(index + 1))))

应该注意的是,我想单击所有未打开的选项卡,但我似乎无法使用 CSS 选择器来查找足够具体的元素,因为我相信在这种情况下它不允许您缩小类元素的范围。

有没有办法解决这个不点击所有内容的问题?

需要注意的是,我正在使用...

对于索引中的索引:

indexes = [index for index in range(len(options))]
shuffle(indexes)
for index in indexes:

有没有更优雅的使用 for 1 循环的方法?

[import sys
sys.exit()][1]

Full code https://pastebin.com/jbg7wyE3


这会一一循环每个联赛的所有比赛,根据需要收集所有相关数据。您可以通过在每个查询前添加前缀来收集每个匹配中的更多数据.并通过选择匹配match.find_element_by_xpath('.//your-query-here')。让我知道这是否有效!

import sys, io, os, csv, requests, time
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium import webdriver

driver = webdriver.Chrome()
driver.set_window_size(1024, 600)
driver.maximize_window()

try:
    os.remove('vtg121.csv')
except OSError:
    pass

driver.get('https://www.unibet.com.au/betting#filter/football')
time.sleep(1)

clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, 
    ('//div[@class="KambiBC-collapsible-container '\
    'KambiBC-mod-event-group-container"]'))))
time.sleep(0)

xp_opened = '//div[contains(@class, "KambiBC-expanded")]'
xp_unopened = '//div[@class="KambiBC-collapsible-container ' \
    'KambiBC-mod-event-group-container" ' \
    'and not(contains(@class, "KambiBC-expanded"))]'
opened = driver.find_elements_by_xpath(xp_opened)
unopened = driver.find_elements_by_xpath(xp_unopened)

data = []
for league in opened:
    xp_matches = './/li[contains(@class,"KambiBC-event-item")]'
    matches = league.find_elements_by_xpath(xp_matches)

    try:
        # League Name
        xp_ln = './/span[@class="KambiBC-mod-event-group-header__main-title"]'
        ln = league.find_element_by_xpath(xp_ln).text.strip()
    except:
        ln = None
    print(ln)

    for match in matches:
        # get all the data per 'match group'
        xp_team1_name = './/button[@class="KambiBC-mod-outcome"][1]//' \
            'span[@class="KambiBC-mod-outcome__label"]'
        xp_team1_odds = './/button[@class="KambiBC-mod-outcome"][1]//' \
            'span[@class="KambiBC-mod-outcome__odds"]'
        xp_team2_name = './/button[@class="KambiBC-mod-outcome"][3]//' \
            'span[@class="KambiBC-mod-outcome__label"]'
        xp_team2_odds = './/button[@class="KambiBC-mod-outcome"][3]//' \
            'span[@class="KambiBC-mod-outcome__odds"]'

        try:
            team1_name = match.find_element_by_xpath(xp_team1_name).text
        except:
            team1_name = None

        try:
            team1_odds = match.find_element_by_xpath(xp_team1_odds).text
        except:
            team1_odds = None

        try:
            team2_name = match.find_element_by_xpath(xp_team2_name).text
        except:
            team2_name = None

        try:
            team2_odds = match.find_element_by_xpath(xp_team2_odds).text
        except:
            team2_odds = None

        data.append([ln, team1_name, team1_odds, team2_name, team2_odds])

for league in unopened:
    league.click()
    time.sleep(0.5)
    matches = league.find_elements_by_xpath(xp_matches)

    try:
        ln = league.find_element_by_xpath(xp_ln).text.strip()
    except:
        ln = None
    print(ln)

    for match in matches:
        try:
            team1_name = match.find_element_by_xpath(xp_team1_name).text
        except:
            team1_name = None

        try:
            team1_odds = match.find_element_by_xpath(xp_team1_odds).text
        except:
            team1_odds = None

        try:
            team2_name = match.find_element_by_xpath(xp_team2_name).text
        except:
            team2_name = None

        try:
            team2_odds = match.find_element_by_xpath(xp_team2_odds).text
        except:
            team2_odds = None

        data.append([ln, team1_name, team1_odds, team2_name, team2_odds])

with open('vtg121.csv', 'a', newline='', encoding="utf-8") as outfile:
    writer = csv.writer(outfile)
    for row in data:
        writer.writerow(row)
        print(row)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

不单击所有选项卡并且不循环一次问题 的相关文章

随机推荐

  • 循环遍历数据框以按城市删除异常值(调用函数)

    我有一个包含日期 城市 销售额的数据框 Date City Sales 2008 01 01 C1 10000 2008 01 01 C2 2000 2008 01 02 C1 13000 2008 01 02 C2 5000 and so
  • 打印到达第 n 级楼梯的方法

    我最近在面试中遇到了这个问题 有n楼梯 一个人站在底部想要到达顶部 该人一次可以爬 1 级楼梯或 2 级楼梯 打印出人们到达顶峰的所有可能方式 例如 n 4输出 1 2 3 4 1 2 4 1 3 4 2 3 4 2 4 但我无法正确编码
  • MPAndroidChart BarChart水平/垂直

    我正在使用MPAndroid图表 https github com PhilJay MPAndroidChart图书馆 在 BarChart 中 默认情况下所有条形都是垂直的 自下而上 如何将其水平显示 有两种类型条形图的方向 The no
  • Python3 递归求和整数的数字

    我需要帮助实现一个函数 该函数将获取整数的数字并将它们加在一起 只要 sumDigits 函数实现了递归 它就有效 并且 main 函数必须保持原样 我将在下面包含一个模板 def sumdigits value recursively s
  • 在 Windows 2008 Server 中从 MP3/WAV 文件生成视觉(波形)?

    是否有 某处 适用于 Windows 的命令行程序可以从 MP3 WAV 创建 PNG JPEG 视觉效果 EDIT This is a good example of how the image should look like Sox
  • Stream.CopyTo() 方法可以保存不完整的流吗?

    我有一个 WCF 服务 它允许我分块上传文件 我想知道的是 在任何情况下 这段代码是否会导致上传的流仅部分附加到目标流 我的日志显示所有发送的流都是 512000 字节 我在客户端设置 并且到目前为止我已经发送了 9 个块中的 6 个块 但
  • Facebook 需要 CURL PHP 扩展

    我正在尝试在我的 apache 服务器上运行我的第一个 facebook php 应用程序 它给出了错误Facebook needs the CURL PHP extension 我已经添加了行extension php curl dll在
  • 哪个版本的 Grails 支持 JDK 8?

    我正在为 Grails 使用以下配置 Grails 版本 2 4 0 Maven版本3 2 5 JDK版本1 8 0 51 当我运行服务器时 我收到两个错误 在我的 POM 中 我使用grail gorm and grail crud依赖关
  • 使用 ruby​​/fastercsv 将 CSV 文件合并到公共字段上

    我有一个包含许多列的 主 文件 1 2 3 4 5 我还有一些其他文件 其行数比主文件少 每个文件的列数 1 6 我想合并这些匹配的文件在第 1 列字段上并将第 6 列添加到主字段 我见过一些 python UNIX 解决方案 但如果合适的
  • 加载数据问题

    数据链接 Data https www dropbox com s yt4l10nel5bwxoq GTAP ConsIndex csv Code ccfsisims lt read csv file F Purdue University
  • VS2010:自动生成的文件和 XML 文档

    这真的只是重新询问这个问题询问有关 Visual Studio 2008 https stackoverflow com questions 1445723 vs2008 autogenerated files and xml docume
  • Django 管理表格内联查找选择下拉框用于非常大的查询集

    我有一个 django admin 表格内联 其中我有form ProdForm其中持有一个modelchoicefield选择框如下 class ProdForm forms ModelForm productid forms Model
  • 分叉与线程

    我以前在我的应用程序中使用过线程并且很了解它的概念 但最近在我的操作系统讲座中我遇到了 fork 这与线程类似 我用谷歌搜索了它们之间的区别 我发现 Fork只不过是一个新进程 看起来与旧进程或父进程一模一样 但它仍然是一个不同的进程 具有
  • 当我在 iOS13.2 中加载 WKWebView 时,为什么会收到控制台警告:[Process] Kill() 返回意外错误 1?

    自从我安装了iOS 13 2 测试版 我收到了调试控制台错误消息 每次我在情节提要中加载带有 WKWebView 对象的 ViewController 时 都会发生这种情况 然后 当 Web 视图可见时 会连续显示以下消息 2019 10
  • Cordova SQLite:无法读取 null 的属性“事务”

    我正在尝试将 SQLite 集成到我的 Ionic 应用程序中 但我不断收到Cannot read property transaction of null通过浏览器进行远程调试或测试时 尝试在数据库中查询设备上的数据时 因此 我将所有配置
  • xml.etree 还是 xml.dom?

    我正在尝试读取一些 xml 但我不确定应该使用哪个库 xml etree 和 xml dom 哪个更好 为什么 请解释你的答案并给出论点 另外 您认为其中之一会被弃用吗 哪一个 两者都不会被弃用 元素树 http effbot org zo
  • 多个插入的行 ID

    我一次插入多行 如下所示 INSERT INTO person VALUES joe 50 jon 24 然后我需要使用他们的 id 将上面的内容链接到另一个表 通常我会使用LAST INSERT ID INSERT INTO hobbie
  • 如何使用 JavaScript 统计我网站上的访问者数量?

    我需要一个计数器来集成到我的 HTML 代码中 当访问者访问我的网页时 该计数器从一计数到三 例如 如果第一个访问者访问我的页面 则计数为 1 那么下一个访问者访问该页面 则计数为 2 对于第三个访问者 计数为 3 然后对于第四个访问者 又
  • 如何查看google app脚本项目的源代码?

    所以我想以任何方式知道 我们是否可以看到提供了以 exec 结尾的 Web 应用程序 URL 的应用程序脚本项目的源代码 提前致谢 如果您不拥有该脚本或在 Google 云端硬盘中没有与您共享该脚本 则无法查看服务器端代码
  • 不单击所有选项卡并且不循环一次问题

    I am trying to click the tabs on the webpage as seen below Unfortunately it only seems to click some of the tabs despite