就像标题所说的那样,我在使用Python 3的urllib模块时遇到了问题。 我的代码:
import urllib.request
WORD_URL = "http://learnpythonthehardway.org/words.txt"
for word in urllib.request.urlopen(WORD_URL).read():
WORDS.append(word.strip())
我的错误是:
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
但是当我在谷歌手动转到它时,链接工作正常。 感谢任何帮助。谢谢。
答案 0 :(得分:0)
URL确实链接到不存在的页面。 点击:http://learnpythonthehardway.org/words.txt
根据您的写作,我想您在Google搜索中输入了网址。那是不一样的。
答案 1 :(得分:0)
切换
"http://learnpythonthehardway.org/words.txt"
到
"http://learncodethehardway.org/words.txt"
您应该有一个工作程序,但.read()
会返回一个单词列表。你必须解析它们并删除一些字符。