'unicode' object is not callable

sidooh 2010-08-05 03:01:37
import lxml.html
import urllib

num=1
while(num<=5):
url = "http://www.sdzk.gov.cn/score/gaokao/2010/100804/Book"
final_url = "http://www.sdzk.gov.cn/score/gaokao/2010/100804/Book"+str(num)+".htm"
page = urllib.urlopen(final_url)
str = page.read().decode("gb2312")


doc = lxml.html.fromstring(str)
name_ele = doc.cssselect("td")


i = 26
plan = 0
post = 0
while(i<len(name_ele)):
if((i-26)%11==0):
try:
plan = int(name_ele[i+6].text)
post = int(name_ele[i+8].text)
print "%s,%d" % (name_ele[i].text,plan-post)
except TypeError:
print "None"
i = i+1

num = num+1

大家好,我写的这个程序最外面的循环第一次循环时没问题,第二次循环时便出现如下错误:
(第七行)TypeError: 'unicode' object is not callable

我不明白哪个是'unicode' object?
我改为
try:
final_url = "http://www.sdzk.gov.cn/score/gaokao/2010/100804/Book"+str(num)+".htm"
except ValueError:
final_url = "http://www.sdzk.gov.cn/score/gaokao/2010/100804/Book"+num+".htm"

便出现不能将数字与字符串直接连接的错误了

我该怎么办?希望大家帮帮我(我用的是python 2.5)
...全文
570 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sidooh 2010-08-05
  • 打赏
  • 举报
回复
换了变量名后果然没有错误了

非常感谢!
angel_su 2010-08-05
  • 打赏
  • 举报
回复
str = page.read().decode("gb2312")这个不好吧!str是内建字,应避开使用,不然再次str(num)就用你定义的str,那么就出问题了,变成要全名调用__builtins__.str(num)写着烦了...

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧