word1 = 'index.php/1'
word2 = 'index.php/2'
try:
tentativa1 = urllib2.urlopen(site + word1)
tentativa2 = urllib2.urlopen(site + word2)
except URLError as e:
tentativa1 = e
tentativa2 = e
lista = [tentativa1, tentativa2]
for website in lista:
if website.code == 200:
website = website.read()
print '\n:)' if 'registration' in website else '\n:/'
print '\n:)' if 'there is no form' in website else '\n:/'
我没有收到错误但是没有打印它应该是什么。想法是输入一个用两个或多个字符串连接的网站,然后是“.read()”如果找到“keywords”将打印“:)”。
答案 0 :(得分:0)
你可以尝试这段代码并告诉我什么是打印输出
sites = [site + 'index.php/1', site + 'index.php/2']
for url in sites:
try:
website = urllib2.urlopen(url)
except URLError as e:
print '{}: {}'.format(url, repr(e))
else:
if website.code == 200:
website = website.read().lower()
print '\n:)' if 'registration' in website else '\n:/'
print '\n:)' if 'there is no form' in website else '\n:/'
else:
print '{}: code {}'.format(url, website.code)