List ';请求';当网页包含在列表中时,模块未正确ping网页

List ';请求';当网页包含在列表中时,模块未正确ping网页,list,python-3.x,python-requests,List,Python 3.x,Python Requests,我正在使用request模块查看单词列表中的项目是否是位于的文章。我目前的代码是: import requests words = ['no', 'yes', 'thermodynamics', 'london', 'Max-Factor', 'be'] for word in words: request = requests.head('https://www.britannica.com/topic/' + word.lower()) if request.status

我正在使用request模块查看单词列表中的项目是否是位于的文章。我目前的代码是:

import requests

words = ['no', 'yes', 'thermodynamics', 'london', 'Max-Factor', 'be']

for word in words:
    request = requests.head('https://www.britannica.com/topic/' + word.lower())
    if request.status_code == 200:
        print(">EXISTS")
        print('https://www.britannica.com/topic/' + word.lower())
        print("<")
    else:
        print(">DOESNT EXIST")
        print('https://www.britannica.com/topic/' + word.lower())
        print("<")
导入请求
单词=[“否”、“是”、“热力学”、“伦敦”、“最大系数”、“be”]
用文字表示:
request=requests.head('https://www.britannica.com/topic/“+word.lower())
如果request.status_code==200:
打印(“>存在”)
打印('https://www.britannica.com/topic/“+word.lower())
打印(“不存在”)
打印('https://www.britannica.com/topic/“+word.lower())

打印(显然,britanica.com使用重定向,可能是为了负载平衡,因此您通常会获得状态
301
,而不是
200
请求
模块可以在使用以下重定向的情况下继续执行:

request = requests.head('https://www.britannica.com/topic/' + word.lower(),
                        allow_redirects=True)

for
循环下缩进
if..else
块怎么样?@zwer已修复,现在与原始代码相同。还值得注意的是
允许重定向
通常默认为
True
,但
head
默认为
False