TypeError: __init__() got an unexpected keyword argument 'restrict_xpath'
TypeError: __init__() got an unexpected keyword argument 'restrict_xpath'
我是 scrapy 的新手,在尝试 运行 我的蜘蛛时遇到了以下问题。© 阅读了很多有关规则 class 的内容,但仍然无法找出错误。我错过了什么,是因为回调参数的语法
代码如下:
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
class ParserSpider(CrawlSpider):
name = 'parser'
allowed_domains = ['eksisozluk.com/']
start_urls = ['https://eksisozluk.com//']
rules = (
Rule(LinkExtractor(restrict_xpath='//div[@id="mobile-index"]/ul/li'),callback='parse_item', follow=True),
Rule(LinkExtractor(restrict_xpath='//div[@id="topic"]/div[1]/div[2]/a[2]'))
)
def parse_item(self, response):
yield {
'title': response.xpath("//h1[@id='title']/text()").get(),
'entry': response.xpath("//div[@class='content']text()").get(),
'yazar': response.xpath("//a[@class='entry-author']/text()").get(),
'title': response.xpath("//a[@class='entry-date permalink']/text()").get(),
}
并输出:
File "/home/bodhi/Desktop/scrape_projects/eksi_parser/eksi_parser/spiders/parser.py", line 6, in <module>
class ParserSpider(CrawlSpider):
File "/home/bodhi/Desktop/scrape_projects/eksi_parser/eksi_parser/spiders/parser.py", line 12, in ParserSpider
Rule(LinkExtractor(restrict_xpath='//div[@id="mobile-index"]/ul/li'),callback='parse_item', follow=True),
TypeError: __init__() got an unexpected keyword argument 'restrict_xpath'
正确的参数是 restrict_xpaths
,s
而不是 restrict_xpath
。
我是 scrapy 的新手,在尝试 运行 我的蜘蛛时遇到了以下问题。© 阅读了很多有关规则 class 的内容,但仍然无法找出错误。我错过了什么,是因为回调参数的语法
代码如下:
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
class ParserSpider(CrawlSpider):
name = 'parser'
allowed_domains = ['eksisozluk.com/']
start_urls = ['https://eksisozluk.com//']
rules = (
Rule(LinkExtractor(restrict_xpath='//div[@id="mobile-index"]/ul/li'),callback='parse_item', follow=True),
Rule(LinkExtractor(restrict_xpath='//div[@id="topic"]/div[1]/div[2]/a[2]'))
)
def parse_item(self, response):
yield {
'title': response.xpath("//h1[@id='title']/text()").get(),
'entry': response.xpath("//div[@class='content']text()").get(),
'yazar': response.xpath("//a[@class='entry-author']/text()").get(),
'title': response.xpath("//a[@class='entry-date permalink']/text()").get(),
}
并输出:
File "/home/bodhi/Desktop/scrape_projects/eksi_parser/eksi_parser/spiders/parser.py", line 6, in <module>
class ParserSpider(CrawlSpider):
File "/home/bodhi/Desktop/scrape_projects/eksi_parser/eksi_parser/spiders/parser.py", line 12, in ParserSpider
Rule(LinkExtractor(restrict_xpath='//div[@id="mobile-index"]/ul/li'),callback='parse_item', follow=True),
TypeError: __init__() got an unexpected keyword argument 'restrict_xpath'
正确的参数是 restrict_xpaths
,s
而不是 restrict_xpath
。