我是新来的。我想从一个日本网站上抓取一些数据,但是当我运行下面的蜘蛛时,它不会在导出的文件上显示任何数据。有人能帮帮我吗。在
导出为csv格式也不会在shell中显示任何结果,只是[]
。在
这是我的密码。在
import scrapy
class suumotest(scrapy.Spider):
name = "testsecond"
start_urls = [
'https://suumo.jp/jj/chintai/ichiran/FR301FC005/?tc=0401303&tc=0401304&ar=010&bs=040'
]
def parse(self, response):
# for following property link
for href in response.css('.property_inner-title+a::attr(href)').extract():
yield scrapy.Request(response.urljoin(href), callback=self.parse_info)
# defining parser to extract data
def parse_info(self, response):
def extract_with_css(query):
return response.css(query).extract_first().strip()
yield {
'Title': extract_with_css('h1.section_title::text'),
'Fee': extract_with_css('td.detailinfo-col--01 span.detailvalue-item-accent::text'),
'Fee Descrition': extract_with_css('td.detailinfo-col--01 span.detailvalue-item-text::text'),
'Prop Description': extract_with_css('td.detailinfo-col--03::text'),
'Prop Address': extract_with_css('td.detailinfo-col--04::text'),
}
parse
方法中的第一个css选择器出现故障:
^{pr2}$+
是这里的错误。只需将其替换为空格,例如:另一个问题是在您定义的
extract_with_css()
函数中:这里的问题是如果找不到值,
extract_first()
将在默认情况下返回None
,并且.strip()
是string
基类的函数,因为没有得到字符串,这将引发错误。要修复此问题,可以将默认值设置为
extract_first
为空字符串:相关问题 更多 >
编程相关推荐