Python 如何删除scrapy函数中的项目名称?

Python 如何删除scrapy函数中的项目名称?,python,scrapy,Python,Scrapy,当运行编码时,它会给我项目价格,但项目名称是相同的。表示它给出转录价格:245,然后给出转录价格:240。应该有caption\u price和transcription\u price。为什么以及如何解决这个问题 import scrapy from .. items import FetchingItem import re class SiteFetching(scrapy.Spider): name = 'Site' start_urls = ['https://www.rev.com

当运行编码时,它会给我项目价格,但项目名称是相同的。表示它给出
转录价格:245
,然后给出
转录价格:240
。应该有
caption\u price
transcription\u price
。为什么以及如何解决这个问题

import scrapy
from .. items import FetchingItem
import re

class SiteFetching(scrapy.Spider):
name = 'Site'
start_urls = ['https://www.rev.com/freelancers/transcription',
          'https://www.rev.com/freelancers/captions']

def parse(self, response):
    items = FetchingItem()
    Transcription_price = response.css('#middle-benefit .mt1::text').extract()

    items['Transcription_price'] = Transcription_price

    def next_parse(self, response):
        other_items = FetchingItem()
        Caption_price = response.css('#middle-benefit .mt1::text').extract()

        other_items['Caption_price'] = Caption_price
        yield other_items

    yield items

您的代码永远无法到达方法
self.next\u parse
。默认情况下,Scrapy调用回调
self.parse
self.start\u URL
中的每个URL。 您可以通过覆盖方法
start\u requests
来使用自定义回调

以下是您的操作方法:

import scrapy
from .. items import FetchingItem
import re

class SiteFetching(scrapy.Spider):
    name = 'Site'

    def start_requests(self):
        return [
            scrapy.Request('https://www.rev.com/freelancers/transcription', callback=self.parse_transcription),
            scrapy.Request('https://www.rev.com/freelancers/captions', callback=self.parse_caption)
        ]

    def parse_transcription(self, response):
        items = FetchingItem()
        Transcription_price = response.css('#middle-benefit .mt1::text').extract()

        items['Transcription_price'] = Transcription_price
        yield items

    def parse_caption(self, response):
        other_items = FetchingItem()
        Caption_price = response.css('#middle-benefit .mt1::text').extract()

        other_items['Caption_price'] = Caption_price
        yield other_items
有关更多信息,请参阅