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
,name hs
和cross rf
等字词,这些字段是我希望抓取工具检查的内容,如果有这些字词则不执行任何操作
答案 0 :(得分:0)
您可以使用xpath
选择器检查内部文字,因此如果您希望获得内部文字td
的所有Active
,请使用以下内容:
response.xpath('//td[text()="Active"]')
对于其他字符串,您也可以使用:
response.xpath('//td[contains(text(), "Activ")]')
如果您只想要字符串的一部分