如何在运行Python的.read()时定位字符串?

2024-04-26 11:32:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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, ':/'

这样做的目的是确认字符串“\head/”是在页面的源代码中找到的。 我该怎么做


Tags: readifascodewebsiteurllib2headelse