selenium获取页面文本的3种方法

发布时间 2023-06-09 13:46:43作者: 你说夕阳很美
1、find_element
driver.find_element(By.XPATH, value_xpath).text

2、页面元素解析
public_notice = self.driver.page_source
public_notice_parse = BeautifulSoup(public_notice, "lxml")
public_notice_ele = public_notice_parse.find_all(class_='ant-table-tbody')
for tbody in public_notice_ele:
    for tr in tbody:
        td.string
        
3、执行js
js = f"return document.getElementsByClassName('ant-input')[{index}].value"
driver.execute_script(js)