我有两个班,一个是乡村班,另一个是乡村班。我想在countries类中从CountriesSpider调用parse()函数,但出现了以下错误
TypeError: parse() missing 1 required positional argument: 'response'
请注意:def parse(self,response)是类scrapy.Spider的一个内置函数,它接受reponse参数
如何从countries类调用this函数self.countriesSpider.parse()
import scrapy
import cherrypy
class CountriesSpider(scrapy.Spider):
name = 'countries'
allowed_domains = ['www.worldometers.info/']
start_urls = ['https://www.worldometers.info/world-population/population-by-country/']
def parse(self, response):
title = response.xpath("//h1/text()").get()
countries = response.xpath("//td/a/text()").getall()
yield {
'title': title,
'countries': countries
}
return countries
class Countries(object):
def __init__(self):
# Create an instance of Snacks class
self.countriesSpider = CountriesSpider()
@cherrypy.expose
def index(self):
return self.countriesSpider.parse()
if __name__ == '__main__':
cherrypy.quickstart(Countries())
函数需要一个名为response的参数。您没有输入参数
相关问题 更多 >
编程相关推荐