我在一个网站上搜索一个字符串,并检查这个字符串的位置是否在预期的位置。我知道字符串从第182个字符开始,如果我打印temp,它甚至会告诉我它是182,但是if语句说182不是182。在
f = urllib.urlopen(link)
#store page contents in 's'
s = f.read()
f.close()
temp = s.find('lettersandnumbers')
if (htmlsize == "197"):
#if ((s.find('lettersandnumbers')) == "182"):
if (temp=="182"):
print "Glorious"
doStuff()
else:
print "HTML not correct. Aborting."
else:
print htmlsize
print "File size is incorrect. Aborting."
^{} returns integer, not string 。字符串整数比较始终返回
False
。在我不是Python大师,但我会试试看
这样试试吧
为什么?见SilentGhost答案。它涉及类型
相关问题 更多 >
编程相关推荐