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/