【问题标题】:Web Scraping XML file that's Downloaded After Submitting Form (Python)提交表单后下载的 Web 抓取 XML 文件 (Python)
【发布时间】: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


【解决方案1】:

stackoverflow 上的这篇文章似乎是我正在寻找的方向; How to download XML files avoiding the popup This type of file may harm your computer through ChromeDriver and Chrome using Selenium in Python

这个链接对我的需求帮助最大,所以我会在这里添加它,但是,第一个链接也很有帮助,所以我想离开它。 How to control the download of files with Selenium + Python bindings in Chrome

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-01
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多