Pergunta

i'm using urllib2

try:
    msmalvo = urllib2.urlopen(website)
except URLError as e:
    msmalvo = e

if msmalvo.code == 200:
    if msmalvo.read() == '<head>':
        print 'Exits!'

    else:
        print 'Don't exist'

else:
    print ' '
    print msmalvo.code, ':/'

the idea is to confirm that the string "\head/" was found in the source code of a page. How can I do this ?

Foi útil?

Solução

Simply do:

'<head>' in msmalvo.read()

instead of:

msmalvo.read() == '<head>'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top