iT邦幫忙

0

{已解決}Python selenium 彈出分頁後點選問題

  • 分享至 

  • xImage

各位前輩好
目前正在練習以Python selenium抓取資料,但在主頁面點選查詢資料後後彈出新的頁面
嘗試過切換頁面繼續操作下載csv檔案卻無法下載,但python卻是顯示程式碼已經跑完了
在煩請各位高手指教,謝謝

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time


browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get("https://e-service.cwb.gov.tw/HistoryDataQuery/")
time.sleep(5)
select1 = Select(browser.find_element(By.ID,'stationCounty'))
select1.select_by_value("桃園市")
time.sleep(3)
select2 = Select(browser.find_element(By.ID,'station'))
select2.select_by_value("C0C670")
time.sleep(3)
select3 = Select(browser.find_element(By.ID,'datatype'))
select3.select_by_value("day")
time.sleep(3)

select6 = browser.find_element(By.XPATH,"/html/body/div[1]/div/div[2]/form/div[1]/div[2]/div[2]/table/tbody/tr[5]/td/input").send_keys('2020-10-08')
time.sleep(1)

browser.find_element(By.XPATH,'//*[@id="doquery"]').click()
time.sleep(5)

window= browser.window_handles[1]
browser.switch_to.window(window)
print(browser.title)
time.sleep(3)

select7 = browser.find_element(By.CSS_SELECTOR,'a[id = downloadCSV]')
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答