【发布时间】:2023-03-25 11:43:01
【问题描述】:
提交表单后如何抓取自动下载到计算机的 xml 文件?我还没有看到任何包含来自提交数据的文件的示例。我无法在 python 文档中找到它。 https://docs.python.org/3/library/xml.etree.elementtree.html 。任何建议或链接将不胜感激。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
url = 'https://oui.doleta.gov/unemploy/claims.asp'
driver = webdriver.Chrome(executable_path=r"C:\Program Files (x86)\chromedriver.exe")
driver.implicitly_wait(10)
driver.get(url)
driver.find_element_by_css_selector('input[name="level"][value="state"]').click()
Select(driver.find_element_by_name('strtdate')).select_by_value('2020')
Select(driver.find_element_by_name('enddate')).select_by_value('2022')
driver.find_element_by_css_selector('input[name="filetype"][value="xml"]').click()
select = Select(driver.find_element_by_id('states'))
# Iterate through and select all states
for opt in select.options:
opt.click()
input('Press ENTER to submit the form')
driver.find_element_by_css_selector('input[name="submit"][value="Submit"]').click()
【问题讨论】:
-
网页抓取一个 xml 文件?你的意思是解析它的内容吗?为什么不使用您链接的 etree 库?
-
是的,我的意思是解析它。我发现了一些让我走上正轨的东西。
标签: python xml web-scraping