我尝试将一个字符串传递给网站,该网站检查是否存在任何诅咒字眼。
我尝试将url传递给urlopen(),就像文档urllib.request.urlopen(url,data)一样,我也尝试将查询字符串传递给data,但无法达到结果
import urllib.request, urllib.parse
def read_text():
quotes = open(r"D:\Courses\Udacity Full Stack Web Developer\Python
Section\movie-quotes.txt")
content_of_files = quotes.read()
char_count = len(content_of_files)
print(content_of_files)
print(f"Total character count is {char_count}")
quotes.close()
check_profanity(content_of_files)
def check_profanity(text_to_check):
url = "www.wdylike.appspot.com/?q="
connection = urllib.request.urlopen(url+text_to_check)
print(connection.read())
connection.close()
read_text()
ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'www.wdylike.appspot.com/?q=Houston, we have a problem. (Apollo 13)\n\nMama always said, life is like a box of chocolates. You never know what you are going to get. (Forrest Gump)\n\nYou cant handle the truth. (A Few Good Men)\n\nI believe everything and I believe nothing. (A Shot in the Dark)'
答案 0 :(得分:0)
将协议部分添加到网址中。
替换:
url = "www.wdylike.appspot.com/?q="
具有:
url = "http://www.wdylike.appspot.com/?q="