1

我正在使用 Beautiful soup 从 Weather Underground 网站中提取数据。我能够得到我想要的确切数据并将其分配给一个变量dayTemp。但是当我尝试使用print dayTemp. 我收到以下错误:

 Traceback (most recent call last):
  File "<pyshell#47>", line 1, in <module>
    print dayTemp
  File "C:\Python27\lib\idlelib\rpc.py", line 595, in __call__
    value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
  File "C:\Python27\lib\idlelib\rpc.py", line 210, in remotecall
    seq = self.asynccall(oid, methodname, args, kwargs)
  File "C:\Python27\lib\idlelib\rpc.py", line 225, in asynccall
    self.putmessage((seq, request))
  File "C:\Python27\lib\idlelib\rpc.py", line 324, in putmessage
    s = pickle.dumps(message)
  File "C:\Python27\lib\copy_reg.py", line 74, in _reduce_ex
    getstate = self.__getstate__
RuntimeError: maximum recursion depth exceeded  

span.string用来从整个元素中获取整数值。变量的类型dayTemp<class 'bs4.element.NavigableString'>

4

2 回答 2

1

看来idle没能泡菜dayTemp。您可以尝试将其显式转换为 Unicode 字符串:

print unicode(dayTemp)
于 2012-11-16T00:41:51.080 回答
0

我认为您只是在寻找dayTemp.get_text()文档

于 2012-11-15T15:51:24.060 回答