I'm using python to write a crawler, since I need to parse html so I import lxml but it comes out an wierd error:
<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'}
Here's a piece of my code:
for c in self.contents:
print type(c)
print c
m = tree.xpath(c['xpath'])
Please help me with these two questions:
Why the type is
dictbut the error says NoneType ?I'm tring to match something in the "tree", but it doesn't work (The website is encoded under GBK, could the encoding type cause this kind of problems ?).