如何对字段进行 scrapy 检查并忽略搜索 link

How can I make scrapy check for a field and ignore searching the link

import scrapy
from scrapy.selector import HtmlXPathSelector
from scrapy.http.request import Request


class SunBizSpider(scrapy.Spider):
name = 'sunbiz'
start_urls = ['http://search.sunbiz.org/Inquiry/CorporationSearch/SearchResults?inquiryType=EntityName&searchNameOrder=A&searchTerm=a']

def parse(self, response):
    leurl = 'http://search.sunbiz.org'
    next_plis = response.xpath("//div[@class='navigationBar'][1]//a[@title='Next List']/@href").extract()
    next_lis = (leurl+ ', '.join(next_plis))
    yield scrapy.Request(next_lis, callback=self.parse)
    for href in response.css('.large-width a::attr(href)'):
        full_url = response.urljoin(href.extract())
        yield scrapy.Request(full_url, callback=self.parse_biz)

def parse_biz(self, response):
    re1='((?:[0]?[1-9]|[1][012])[-:\/.](?:(?:[0-2]?\d{1})|(?:[3][01]{1}))[-:\/.](?:(?:[1]{1}\d{1}\d{1}\d{1})|(?:[2]{1}\d{3})))(?![\d])' #        MMDDYYYY 1
    date = response.xpath('//span').re_first(re1)
    yield {
        'Name': response.css('.corporationName span::text').extract()[1],
        'Date': date,
        'Link': response.url,
        }

正则表达式最有可能找到单词 inact 和 cross reff

正如您在上面看到的,我突出显示了诸如 inactname hscross rf 之类的词,这些词是我希望爬虫检查的项目,如果它有,则不执行任何操作那些话。

您可以使用 xpath 选择器来检查内部文本,因此如果您想要获得所有带有内部文本 Activetd,请使用类似:

response.xpath('//td[text()="Active"]')

其他字符串同理,也可以使用:

response.xpath('//td[contains(text(), "Activ")]')

如果您只想要字符串的一部分