且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取表行文本python selenium

更新时间:2023-02-19 16:59:39

要提取表数据 [Primer,Intermediates,Finishes] ,您可以使用以下任一

To extract the table data [Primers,Intermediates,Finishes] you can use either of the following Locator Strategies:

  • 使用 CSS_SELECTOR :

print([my_text_elem.get_attribute("innerHTML") for my_text_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "table#dataLstSubCat>tbody>tr td>a")))])

  • 使用 XPATH :

    print([my_text_elem.get_attribute("innerHTML") for my_text_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.XPATH, "//table[@id='dataLstSubCat']/tbody/tr//td/a")))])
    

  • 注意:您必须添加以下导入:

  • Note : You have to add the following imports :

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