我正致力于通过Python和Windows任务调度器,从一个内部网站进行每日下载。当我手动操作时,我会进入一个浏览器页面,填写表单上的参数,然后单击“提交”;浏览器告诉我它正在准备下载的CSV文件,过了一段时间后,它会将CSV转储到硬盘上。我有CURL语句,并认为我会尝试这样做,但我不知道如何自动化这一点,我不能使用AutoHotKey之类的东西,因为任务调度器不允许GUI交互。以下是我迄今为止尝试过的方法,但最终得到的只是生成的HTML,而不是CSV下载:import urllib
import urllib2
import time
import shutil
url = <>
str="&"
values = ('sequelPath=<>',
'bdatedate=<>',
'edate=<>'
)
headers = { 'Cookie': JSESSIONID=<>; acStatus_Button1=open; acStatus_Button0=close; acStatus_Button2=close; acStatus_Button3=close',
'Origin': '<>',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Cache-Control': 'max-age=0',
'Referer': 'http://<>/exec/<>',
'Connection': 'keep-alive'
}
data = str.join(values)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
myfile = open('myfile.csv', 'wb')
shutil.copyfileobj(response.fp, myfile)
myfile.close()
任何帮助都将不胜感激。在