可以使用python在线下载javascript生成的CSV文件吗?

时间:2018-11-15 13:22:44

标签: javascript python ajax scrapy cryptocurrency

我正尝试使用python脚本在以下网站上下载CSV文件:https://enroyd.com/Sentiment/,以便随后使用python分析结果。单击链接时将生成文件。

我尝试了很多在线解决方案,但似乎都没有用。对于开放式问题我很抱歉,但是有人有什么建议吗?

我已经尝试过该脚本,但是它不起作用

import os
from selenium import webdriver

browser_profile = webdriver.FirefoxProfile('path')

# add the file_formats to download
file_formats = ','.join(["text/plain",
                         "application/pdf",
                         "application/x-pdf",
                         "application/force-download"])

preferences = {
    "browser.download.folderList": 2,
    "browser.download.manager.showWhenStarting": False,
    "browser.download.dir": os.getcwd(),  # will download to current directory
    "browser.download.alertOnEXEOpen": False,
    "browser.helperApps.neverAsk.saveToDisk": file_formats,
    "browser.download.manager.focusWhenStarting": False,
    "browser.helperApps.alwaysAsk.force": False,
    "browser.download.manager.showAlertOnComplete": False,
    "browser.download.manager.useWindow": False,
    "services.sync.prefs.sync.browser.download.manager.showWhenStarting": False,
    "pdfjs.disabled": True
}

for pref, val in preferences.items():
    browser_profile.set_preference(pref, val)

browser_binary = webdriver.firefox.firefox_binary.FirefoxBinary()
browser = webdriver.Firefox(firefox_binary=browser_binary,
                            firefox_profile=browser_profile)

# set the file name that will be saved as when you download is complete
file_name = 'data.csv'

# goto the link to download the file from it will be automatically
# downloaded to the current directory
file_url = 'https://enroyd.com/Sentiment'
browser.find_element_by_class_name('dt-button buttons-csv buttons-html5 DTTT_button DTTT_button_csv').click()

# verify if the expected file name exists in the current directory
path = os.path.join(os.getcwd(), file_name)
assert os.path.isfile(path)

0 个答案:

没有答案