我正在尝试从以下网站上获取所有相关字段,以便将所有数据加载到电子表格中:
http://yellowpages.com.gh/Home.aspx?
我猜爬行蜘蛛就是我想要的,所以这就是我一直在努力构建的:
但是,在命令提示符下运行此命令时,我收到以下错误:
异常.KeyError:'项目不支持字段:catLink'
发生这种错误的最可能原因是什么?它能和我的xpath格式联系起来吗?或者是因为这只蜘蛛共享相同的信息项目.py文件作为项目中的原始蜘蛛?在
我的项目.py代码如下:
# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html
from scrapy.item import Item, Field
class YellowghItem(Item):
# define the fields for your item here like:
# name = Field()
catName = Field()
catLink = Field()
subcatText = Field()
subcatLink = Field()
company = Field()
more = Field()
address = Field()
postAddress = Field()
city = Field()
region = Field()
mobile = Field()
emailtext = Field()
emailLink = Field()
webtext = Field()
webLink = Field()
#pass
这就是为什么你看到了错误。您的
item.py
文件定义了类YellowghItem
。此类具有类成员catLink
。在但是在你的spider中,你没有实例化这个类。相反,您正在实例化一个
Item()
类。我敢打赌在您的项目中还有另一个名为Item
的类,它没有将catLink
定义为它的成员。在在你的蜘蛛上做这些改变:
scrapy.item import YellowghItem
更改导入在您的
parse
方法中,用以下内容实例化此类的对象:尝试这些更改,我认为您将能够解决此错误。在
希望这有帮助。在
相关问题 更多 >
编程相关推荐