我正在创建一个程序,它将从Web服务器下载.jar(java)文件,方法是读取同一游戏/应用程序的.jad文件中指定的URL.我正在使用Python 3.2.1
我设法从JAD文件中提取JAR文件的URL(每个JAD文件都包含JAR文件的URL),但是您可以想象,提取的值是type()字符串.
这是相关的功能:
def downloadFile(URL=None):
import httplib2
h = httplib2.Http(".cache")
resp, content = h.request(URL, "GET")
return content
downloadFile(URL_from_file)
Run Code Online (Sandbox Code Playgroud)
但是我总是得到一个错误,说上面函数中的类型必须是字节,而不是字符串.我尝试过使用URL.encode('utf-8'),还有字节(URL,encoding ='utf-8'),但我总是得到相同或类似的错误.
所以基本上我的问题是当URL存储在字符串类型中时如何从服务器下载文件?
当我不知道文件URL或文件名时,如何使用python mechanize从aspnetForm submitControl中检索触发Excel文件下载的文件?
带Excel文件的网站网址:http://www.ncysaclassic.com/TTSchedules.aspx?tid = NCFL&year = 2012& stid = NCFL&yearar = 2012&div = U11M01
我正在尝试通过Print 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
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
Submitting...
Response...
Content-Type: …Run Code Online (Sandbox Code Playgroud)