import lxml.html, sys
for arg in sys.argv:
url2 = arg
t = lxml.html.parse(url2)
if arg == "":
url = raw_input("开发者_如何转开发Website URL: ")
t = lxml.html.parse(url)
print t.find(".//title").text
Problem is with [if arg == "":] I want to have something like "if there is no arg, then:", but I don't know how. How can I do that?
Try this:
if len(sys.argv) == 1:
print 'no arg'
Edit: There is one more issue in your code:
for arg in sys.argv:
...
Should be:
for arg in sys.argv[1:]:
...
since the first argument is the python file name itself
精彩评论