다음 코드를 사용하여 Python에서 Selenium을 사용하는 사이트에서 여러 파일을 다운로드하려고합니다.
from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome('chromedriver.exe')
driver.maximize_window()
driver.get('https://www10.goiania.go.gov.br/TransWeb/FuncionariosExportarPopUp.aspx?_=1590514086637')
element = driver.find_element_by_id('WebPatterns_wt12_block_wtMainContent_wtcboReferencia')
all_options = element.find_elements_by_tag_name("option")
selectYear = Select(driver.find_element_by_id("WebPatterns_wt12_block_wtMainContent_wtcboReferencia"))
link = driver.find_element_by_id('WebPatterns_wt12_block_wtMainContent_wtbtnGerar')
for option in all_options[:267]:
print("Value is: %s" % option.get_attribute("value"))
selectYear.select_by_value(option)
link.click()
time.sleep(5000)
그러나 나는이 오류가 발생하고 그것을 해결하는 방법을 모릅니다.
TypeError: argument of type 'WebElement' is not iterable
셀레늄을 사용하는 것은 이번이 처음입니다.
사이트 https://www10.goiania.go.gov.br/TransWeb/FuncionariosExportarPopUp.aspx?_=1590514086637 에서 Referência 드롭 다운 메뉴 에서 각 옵션을 선택 하는 Selenium 및 Python을 사용하여 여러 파일을 다운로드하려면 WebDriverWait 를 유도해야합니다. 에 대한 다음과 같은 사용할 수 있습니다 로케이터 전략 : element_to_be_clickable()
코드 블록 :
driver.get("https://www10.goiania.go.gov.br/TransWeb/FuncionariosExportarPopUp.aspx?_=1590514086637")
select = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='WebPatterns_wt12_block_wtMainContent_wtcboReferencia']"))))
for opt in select.options:
opt.click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Gerar']"))).click()
참고 : 다음 가져 오기를 추가해야합니다.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다