Python Selenium-获取表格单元格内的文本

Python Selenium-获取表格单元格内的文本,python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,试图获取表格单元格中的文本,但没有成功 我正在尝试获取这些单元格中的文本: (th和td) 代码是有效的。它将值打印为普通的“”(空格) 代码: 将“获取属性文本内容”用作,文本将检索仅在视口中可见的文本 driver.get('https://www.komplett.se/product/1165487/datorutrustning/datorkomponenter/chassibarebone/big-tower/phanteks-eclipse-p500-air') parent_

试图获取表格单元格中的文本,但没有成功

我正在尝试获取这些单元格中的文本:

(th和td)

代码是有效的。它将值打印为普通的“”(空格)

代码:

将“获取属性文本内容”用作,文本将检索仅在视口中可见的文本

driver.get('https://www.komplett.se/product/1165487/datorutrustning/datorkomponenter/chassibarebone/big-tower/phanteks-eclipse-p500-air')

parent_table = driver.find_element_by_xpath("/html/body/div[2]/main/div[2]/div[2]/div[3]/div/div[2]/div/section[2]/div/div/div")
count_of_tables = len(parent_table.find_elements_by_xpath("./table"))

for x in range(count_of_tables):
    parent_tr = driver.find_element_by_xpath(f"/html/body/div[2]/main/div[2]/div[2]/div[3]/div/div[2]/div/section[2]/div/div/div/table[{x + 1}]/tbody")
    count_of_tr = len(parent_tr.find_elements_by_xpath("./tr"))
    print(count_of_tr)
    for y in range(count_of_tr):
        th = driver.find_element_by_xpath(f'/html/body/div[2]/main/div[2]/div[2]/div[3]/div/div[2]/div/section[2]/div/div/div/table[{x + 1}]/tbody/tr[{y+1}]/th')
        td = driver.find_element_by_xpath(f'/html/body/div[2]/main/div[2]/div[2]/div[3]/div/div[2]/div/section[2]/div/div/div/table[{x + 1}]/tbody/tr[{y + 1}]/td')
        print(th.text)
        print(td.text)
for y in range(count_of_tr):
    th = driver.find_element_by_xpath(
        f'/html/body/div[2]/main/div[2]/div[2]/div[3]/div/div[2]/div/section[2]/div/div/div/table[{x + 1}]/tbody/tr[{y+1}]/th')
    td = driver.find_element_by_xpath(
        f'/html/body/div[2]/main/div[2]/div[2]/div[3]/div/div[2]/div/section[2]/div/div/div/table[{x + 1}]/tbody/tr[{y + 1}]/td')
    print(th.get_attribute("textContent"))
    print(td.get_attribute("textContent"))