gpt4 book ai didi

Python,urllib2 模块中的 NameError,但仅在少数网站中

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:16 25 4
gpt4 key购买 nike

website = raw_input('website: ')
with open('words.txt', 'r+') as arquivo:
for lendo in arquivo.readlines():
msmwebsite = website + lendo
try:
abrindo = urllib2.urlopen(msmwebsite)
abrindo2 = abrindo.read()

except URLError as e:
pass

if abrindo.code == 200:
palavras = ['registration', 'there is no form']
for palavras2 in palavras:
if palavras2 in abrindo2:
print msmwebsite, 'up'

else:
pass

else:
pass

它正在工作,但出于某种原因,我在某些网站上遇到了这个错误:

if abrindo.code == 200:
NameError: name 'abrindo' is not defined

如何解决?..................................................... ..................................................... ..................................................... .....................................

最佳答案

pass 替换为 continue。至少做一些错误记录,因为你默默地跳过错误的链接。

如果您的请求导致 URLError,则没有定义变量 abrindo,因此您的错误。

关于Python,urllib2 模块中的 NameError,但仅在少数网站中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20375782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com