2016-08-23 99 views
0

我不確定爲什麼我的代碼無法正常工作。我把它從我的導師逐字複製。爲什麼我的輸出會產生意想不到的結果?

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> 

這究竟是爲什麼?

謝謝!

+0

請提供文本文件的樣本內容。 – albert

+1

http://www.wdyl.com/看起來不是一個有效的去處。 –

+0

WYDL不再有效:https://en.wikipedia.org/wiki/WDYL_(search_engine) – albert

回答

相關問題