为什么我的输出会产生意外结果?

时间:2016-08-23 20:47:58

标签: python url

我不确定为什么我的代码无效。我把它从我的导师那里逐字复制。

import urllib

def read_text():
    quotes = open("C:\Users\Kyle\Desktop\movie_quotes.txt")
    contents_of_file = quotes.read()
    print(contents_of_file)
    quotes.close()
    check_profanity(contents_of_file)


def check_profanity(text_to_check):
    connection = urllib.urlopen("http://www.wdyl.com/profanity?q="+text_to_check)
    output = connection.read()
    print(output)
    connection.close()

read_text()

输出:

<html><head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>404 Not Found</title>
    </head>
    <body text=#000000 bgcolor=#ffffff>
    <h1>Error: Not Found</h1>
    <h2>The requested URL <code>/profanity?q=shot</code> was not found on this server.</h2>
    <h2></h2>
    </body></html>

为什么会这样?

谢谢!

1 个答案:

答案 0 :(得分:0)

www.wdyl.com不再有效了。

您可以改用:http://www.wdylike.appspot.com/?q=foo