开发者

Python url title problem

开发者 https://www.devze.com 2023-02-22 18:45 出处:网络
import lxml.html, sys for arg in sys.argv: url2 = arg t = lxml.html.parse(url2) if arg == \"\": url = raw_input(\"开发者_如何转开发Website URL: \")
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

精彩评论

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