Python if语句未按预期工作

2024-10-01 11:38:37 发布

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

我在一个网站上搜索一个字符串,并检查这个字符串的位置是否在预期的位置。我知道字符串从第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."

Tags: 字符串代码if网站语句findurllibtemp