我使用Python写一个履带式的,因为我需要解析HTML,所以我导入LXML但它出来一个奇怪的错误时:奇怪的蟒蛇错误使用LXML和XPath
<type 'dict'>
{'xpath': '//ul[@id="i-detail"]/li[1]', 'name': u'\u6807\u9898'}
<type 'dict'>
{'xpath': '//ul[@id="i-detail"]/li[1]', 'name': u'\u6807\u9898'}
<type 'dict'>
{'xpath': '//ul[@id="i-detail"]/li[1]', 'name': u'\u6807\u9898'}
Exception in thread Thread-3:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "fetcher.py", line 78, in run
self.extractContent(html)
File "fetcher.py", line 151, in extractContent
m = tree.xpath(c['xpath'])
AttributeError: 'NoneType' object has no attribute 'xpath'
<type 'dict'>
{'xpath': '//ul[@id="i-detail"]/li[1]', 'name': u'\u6807\u9898'}
这里是一片我的代码:
for c in self.contents:
print type(c)
print c
m = tree.xpath(c['xpath'])
请帮我这两个问题:
为什么类型为
dict
但错误说NoneType?我想要匹配“树”中的某些东西,但它不起作用(网站编码在GBK下,编码类型是否会导致这种问题?)。