使用python selenium在p标记中查找表数据

2024-09-29 19:18:57 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,基本上我使用selenium来自动复制表中的数据,并在新选项卡中打开它,并为其创建单独的页面。因此,每个tr都有一个单元格的名称和一张图片。我想从链接中复制单元格的名称和图片,并用它创建一个新页面。访问p标签中的数据的任何帮助都将非常有用!我似乎找不到表的路径,因为它没有id,也不知道如何从td访问p标记

enter image description here

我想复制单元格信息,然后将信息粘贴到新选项卡以创建新页面。我不知道selenium是否是这方面的合适工具

enter image description here


Tags: 数据标记路径名称信息id链接selenium
1条回答
网友
1楼 · 发布于 2024-09-29 19:18:57

您可以使用下面的代码迭代表中的所有行,并从每一行访问单元格名称和图像

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

table = WebDriverWait(driver, 50).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='table-wrap']/table[1]")))
element.click()


for row in table.find_elements_by_xpath(".//tr//td[@class='confluenceTd']/div[1]"):

          cell_name=row.find_element_by_xpath("./p[1]")
          print(cell_name.text)
          image= row.find_element_by_xpath(".//span//img")

相关问题 更多 >

    热门问题