Python webbrowser模块?

时间:2017-02-14 10:36:37

标签: python

我正在尝试使用webbrowser模块,但它不适用于我希望它做的事情。

    import webbrowser

    key="Yes"
    key1="yes"
    key2="No"
    key3="no"

    ques1=input("Would you like us to open a website for you?")
    if ques1 == key or key1:
        webbrowser.open("http://www.wikihow.com/Fix-the-Blue-Screen-of-Death-on-Windows")
    elif ques1 == key2 or key3:
        print("We will open a website for you automatically. http://www.wikihow.com/Fix-the-Blue-Screen-of-Death-on-Windows")

1 个答案:

答案 0 :(得分:0)

那是因为您在 print() 模块中输入了链接! 此代码将起作用:

import webbrowser
key="Yes"
key1="yes"
key2="No"
key3="no"

ques1=input("Would you like us to open a website for you?")
if ques1 == key:
        webbrowser.open("http://www.wikihow.com/Fix-the-Blue-Screen-of-Death-on-Windows")
elif ques1 == key1:
        webbrowser.open("http://www.wikihow.com/Fix-the-Blue-Screen-of-Death-on-Windows")
if ques1 == key2:
        print("We will open a website for you automatically")
        webbrowser.open("https://www.wikihow.com/Fix-the-Blue-Screen-of-Death-on-Windows")
elif ques1 == key3:
         print("We will open a website for you automatically")
         webbrowser.open("https://www.wikihow.com/Fix-the-Blue-Screen-of-Death-on-Windows")