2017-06-20 30 views
-3

我试图让我的程序读取用户插入的网站。我的错误可能非常愚蠢,因为我有点新手,但我无法在任何地方找到答案。为什么urllib不能使用我的python代码?

这是我写的:

def open_website(): 
website = input("Hello, enter website") 
import webbrowser 
webbrowser.open(website) 
find_words() 

def find_words(): 
import urllib 
web_read = urllib.urlopen(website) 
text = web_read.read() 
print (text) 




open_website() 
+2

你忘了告诉我们你收到了什么错误,包括完整的回溯。 –

+1

程序的输出是什么?怎么了?你投入什么? –

回答

1

您使用Python 3.x,你必须使用urllib.requesturllib.urlopen

而且,你必须通过websitefind_words,你的代码改成这样:

def open_website(): 
    website = input("Hello, enter website") 
    import webbrowser 
    webbrowser.open(website) 
    find_words(website) 

def find_words(website): 
    from urllib.request import urlopen 
    web_read = urlopen(website) 
    text = web_read.read() 
    print (text) 

open_website() 
相关问题