开发者

Python url title problem

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜