[英]I am trying to download the Yearly data from this website using python but i am not sure how to approach it?
我想学习如何使用 python 下载过去十年的 CSV 文件。 我认为这会有所帮助。
https://www.usgovernmentspending.com/compare_state_debt
我的尝试涉及请求和 pandas。
问题已解决我设法使用 selenium 解决了它。
通过执行以下操作:
from selenium import webdriver # allow launching browser
# Opening in incognito
driver_option = webdriver.ChromeOptions()
#driver_option.add_argument(" — incognito")
chromedriver_path = '# Write your path here' # Change this to your own chromedriver path!
# Creating a webdriver.
def create_webdriver():
return webdriver.Chrome(executable_path=chromedriver_path, options=driver_option)
URL = ""
browser.get(url)
# Clicking the button.
elem1 = browser.find_element_by_link_text("download file")
# Clicking the button.
elem1.click()
直到 2020 年,我将之前的代码一直循环,我得到了 CSV 格式的所有文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.