Question

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:/'

I'm no getting error but isn't printing what should it. The idea is to input a website concatening with two or more strings, then the ".read()" if find the "keywords" would print ":)".

Was it helpful?

Solution

Can you try this code and say me what print output

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top