传递URL作为参数 [英] Passing a url as argument
本文介绍了传递URL作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我尝试如下运行脚本时,都会得到以下结果.代码有什么问题?
Whenever I try to run the script as below, I get the following results. What is wrong with the code?
1. python test.py
不打印用法.
2. python test.py http://link.com/index.php?title=tesst&action=raw
张照片:"action"不被识别为内部或外部命令,可操作的程序或批处理文件."
我的脚本:
# 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)
推荐答案
将网址用引号引起来:
python test.py "http://link.com/index.php?title=tesst&action=raw"
&
令人困惑的命令提示符.
The &
is confusing Command Prompt.
这篇关于传递URL作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文