|
@@ -6,7 +6,7 @@ import openpyxl
|
|
|
from selenium import webdriver
|
|
|
|
|
|
# 设置Chrome浏览器选项
|
|
|
-from selenium.common import exceptions
|
|
|
+from selenium.common import exceptions, NoSuchElementException, ElementNotInteractableException
|
|
|
from selenium.webdriver.chrome.service import Service
|
|
|
from selenium.webdriver.common.by import By
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
@@ -109,15 +109,18 @@ if __name__ == "__main__":
|
|
|
text = driver.find_element(By.XPATH, '//*[@id="page_default_sections"]/div/div/div/div/div/p[1]/span')
|
|
|
print("网页中段,文本内容:")
|
|
|
print(text.text)
|
|
|
-
|
|
|
- btn_pop = get_element(driver, '/html/body/div[4]/div[3]/div/section/span')
|
|
|
- if btn_pop:
|
|
|
- btn_pop.click()
|
|
|
-
|
|
|
- accept_btn = get_element(driver, '//*[@id="onetrust-accept-btn-handler"]')
|
|
|
- if accept_btn:
|
|
|
- accept_btn.click()
|
|
|
-
|
|
|
+ try:
|
|
|
+ btn_pop = get_element(driver, '/html/body/div[4]/div[3]/div/section/span')
|
|
|
+ if btn_pop:
|
|
|
+ btn_pop.click()
|
|
|
+
|
|
|
+ accept_btn = get_element(driver, '//*[@id="onetrust-accept-btn-handler"]')
|
|
|
+ if accept_btn:
|
|
|
+ accept_btn.click()
|
|
|
+ except ElementNotInteractableException:
|
|
|
+ # 如果元素不存在,则隐藏报错并执行其他操作
|
|
|
+ print("元素不可点击")
|
|
|
+ ''
|
|
|
WebDriverWait(driver, 10).until(
|
|
|
EC.visibility_of_element_located((By.XPATH, '/html/body/main/div/div[4]/div/iframe'))) # iframe是否出现
|
|
|
|
|
@@ -129,8 +132,11 @@ if __name__ == "__main__":
|
|
|
# button = driver.find_element(By.XPATH, '//*[@id="ctl00_MainContent_ucViewControl_IntegratedFedWatchTool_lbPTree"]')
|
|
|
driver.execute_script(
|
|
|
"javascript:__doPostBack('ctl00$MainContent$ucViewControl_IntegratedFedWatchTool$lbPTree','')")
|
|
|
- sleep(2)
|
|
|
+
|
|
|
+ WebDriverWait(driver, 10).until(
|
|
|
+ EC.visibility_of_element_located((By.XPATH, '//*[@id="MainContent_pnlContainer"]/div[3]/div/div/table[2]')))
|
|
|
table = driver.find_element(By.XPATH, '//*[@id="MainContent_pnlContainer"]/div[3]/div/div/table[2]')
|
|
|
+
|
|
|
table.screenshot(r'meeting.png')
|
|
|
print(table.text)
|
|
|
# 按行查询表格的数据,取出的数据是一整行,按空格分隔每一列的数据
|