我在用scrappy shell做一些样本测试
在我输入'response.xpath('//h1/text()').get()'之后
它给了我AttributeError:“Selector”对象没有属性“_default_type”
有人能帮忙吗?
非常感谢
下面是我在终端输入的内容scrapy shell
fetch("https://www.worldometers.info/world-population/population-by-country/")
r = scrapy.Request(url="https://www.worldometers.info/world-population/population-by-country/")
fetch(r)
response.xpath('//h1/text()').get()
在最后一行之前一切都很顺利。在我输入'response.xpath('//h1/text()').get()'后,它抛出一个错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-7a322073163e> in <module>
----> 1 response.xpath('//h1/text()').get()
~/anaconda3/envs/virtual_work/lib/python3.7/site-packages/scrapy/http/response/text.py in xpath(self, query, **kwargs)
117
118 def xpath(self, query, **kwargs):
--> 119 return self.selector.xpath(query, **kwargs)
120
121 def css(self, query):
~/anaconda3/envs/virtual_work/lib/python3.7/site-packages/scrapy/http/response/text.py in selector(self)
113 from scrapy.selector import Selector
114 if self._cached_selector is None:
--> 115 self._cached_selector = Selector(self)
116 return self._cached_selector
117
~/anaconda3/envs/virtual_work/lib/python3.7/site-packages/scrapy/selector/unified.py in __init__(self, response, text, type, root, _root, **kwargs)
84 % self.__class__.__name__)
85
---> 86 st = _st(response, type or self._default_type)
87
88 if _root is not None:
AttributeError: 'Selector' object has no attribute '_default_type'
1条答案
按热度按时间anauzrmj1#
你用的是什么版本的Scrapy?升级到最新版本就解决了这个问题。