每当我尝试运行下面的脚本时,我都会得到以下结果。代码有什么问题吗?
1.python test.py
不打印用法。
2.python test.py http://link.com/index.php?title=tesst&action=raw
印刷:"'action' is not recognized as an internal or external command,
operable program or batch file."
我的脚本:
# Version YYYYMMDD
version = "20121112"
# File type to be output to logs
# Should be changed to exe before building the exe.
fileType = "py"
# Import sys to read command line arguments
import sys, getopt
#import pdb
#pdb.set_trace()
import argparse
def update (url):
req = urllib2.Request(url=url)
try:
f = urllib2.urlopen(req)
txt = f.read()
f.close()
except urllib2.HTTPError, e:
txt = ''
print 'An error occured connecting to the wiki. No wiki page will be generated.'
return '<font color=\"red\">QWiki</font>'
# Find the start tag of the textarea with Regular Expressions
p = re.compile('<textarea[^>]*>')
m = p.search(txt)
(tagStart, tagEnd) = m.span()
# Find the end of the textarea
endTag = txt.index("</textarea>")
def main ():
#For logging
print "test"
parser = argparse.ArgumentParser(description='This is the update.py script created by test')
parser.add_argument('-u','--ur',action='store',dest='url',default=None,help='<Required> url link',required=True)
results = parser.parse_args()# collect cmd line args
url = results.url
print url
update(url)
将 URL 括在引号中:
python test.py "http://link.com/index.php?title=tesst&action=raw"
The &
令人困惑的命令提示符。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)