当我不知道文件的URL或文件名时,如何使用python mechanize从触发Excel文件下载的aspnetForm submitControl中检索文件?在
包含Excel文件的网站的URL:http://www.ncysaclassic.com/TTSchedules.aspx?tid=NCFL&year=2012&stid=NCFL&syear=2012&div=U11M01
我正在尝试通过打印Excel“按钮”下载文件。在
到目前为止,我已经:
r = br.open('http://www.ncysaclassic.com/TTSchedules.aspx?tid=NCFL&year=2012&stid=NCFL&syear=2012&div=U11M01')
html = r.read()
# Show the html title
print br.title()
# Show the available forms
for f in br.forms():
print f
br.select_form('aspnetForm')
print '\n\nSubmitting...\n'
br.submit("ctl00$ContentPlaceHolder1$btnExtractSched")
print 'Response...\n'
print br.response().info()
print br.response().read
print 'still alive...\n'
for prop, value in vars(br.response()).iteritems():
print 'Property:', prop, ', Value: ', value
print 'myfile...\n'
myfile = br.response().read
我得到这个输出:
^{pr2}$好像我很亲近…注意内容类型:应用程序/越南盾-excel表格
我只是不知道下一步该怎么办。我的文件在哪里?如何获取指向它的指针并将其保存在本地以供以后访问?在
更新:
我使用dir()获取response()的方法/属性列表,然后尝试了几个方法。。。在
print '\ndir(br.response())\n'
for each in dir(br.response()):
print each
print '\nresponse info...\n'
print br.response().info()
print '\nresponse geturl\n'
print br.response().geturl()
我得到这个输出。。。在
dir(br.response())
__copy__
__doc__
__getattr__
__init__
__iter__
__module__
__repr__
__setattr__
_headers
_seek_wrapper__cache
_seek_wrapper__have_readline
_seek_wrapper__is_closed_state
_seek_wrapper__pos
_seek_wrapper__read_complete_state
close
get_data
geturl
info
invariant
next
read
readline
readlines
seek
set_data
tell
wrapped
xreadlines
response info...
Date: Thu, 27 Sep 2012 20:55:02 GMT
ETag: W/"fa759b5df29ccd1:0"
Server: Microsoft-IIS/7.5
Connection: Close
Content-Type: application/vnd.ms-excel
X-Powered-By: ASP.NET
Accept-Ranges: bytes
Last-Modified: Thu, 27 Sep 2012 20:55:03 GMT
Content-Length: 691200
response geturl
http://www.ncysaclassic.com/photos/pdftemp/ScheduleExcel165502.xls
我想我已经在我的br.响应. 我只是不知道怎么提取它!请帮忙。在
相关问题 更多 >
编程相关推荐