我正在尝试使用scrapy,我是一个初学者,因此一些明显的想法不太清楚。我加载了一个用于刮除引号的示例,它可以工作,但似乎无法使代码正确地用于其他任何事情。
import scrapy
class SpidyQuotesViewStateSpider(scrapy.Spider):
name = 'sheriff-viewstate'
start_urls = ['http://www.ascensionsheriff.com/sheriffsale.aspx']
download_delay = 1.5
def parse(self, response):
scrapy.FormRequest(
'http://www.ascensionsheriff.com/sheriffsale.aspx',
formdata={
'rcbInput': 'Real Estate', #'tag': 'tag value'
'__VIEWSTATE': response.css('input#__VIEWSTATE::attr(value)').extract_first()
},
callback=self.parse_tags
)
def parse_tags(self, response):
yield scrapy.FormRequest(
'http://www.ascensionsheriff.com/sheriffsale.aspx',
formdata={
'rcbInput': response.css(
'rcbInput > option[selected] ::attr(value)'
).extract_first(),
'rcbInput radPreventDecorate': 'Next Upcoming Sale Date',
'__VIEWSTATE': response.css('input#__VIEWSTATE::attr(value)').extract_first()
},
callback=self.parse_results,
)
def parse_results(self, response):
for this in response.css("td"):
#pass
print this.css ('tr ::text').extract_first()
我整天都在努力,似乎没有任何结果。有人可以帮我弄清楚它是如何工作的,并正确地做它,以便我可以了解自己在做错什么并继续前进。
Here is the output log
2019-05-01 07:37:21 [scrapy.utils.log] INFO: Scrapy 1.6.0 started (bot: quotes)
2019-05-01 07:37:21 [scrapy.utils.log] INFO: Versions: lxml 4.3.2.0, libxml2 2.9.4, cssselect 1.0.3, parsel 1.5.1, w3lib 1.20.0, Twisted 16.4.1, Python 2.7.16 (default, Apr 6 2019, 01:42:57) - [GCC 8.3.0], pyOpenSSL 19.0.0 (OpenSSL 1.1.1b 26 Feb 2019), cryptography 2.6.1, Platform Linux-4.9.0-8-amd64-x86_64-with-debian-buster-sid
2019-05-01 07:37:21 [scrapy.crawler] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'quotes.spiders', 'SPIDER_LOADER_WARN_ONLY': True, 'SPIDER_MODULES': ['quotes.spiders'], 'LOG_FILE': 'sherriff.log', 'BOT_NAME': 'quotes'}
2019-05-01 07:37:21 [scrapy.extensions.telnet] INFO: Telnet Password: 92208354c38511fc
2019-05-01 07:37:21 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.logstats.LogStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.corestats.CoreStats']
2019-05-01 07:37:21 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2019-05-01 07:37:21 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
'scrapy.spidermiddlewares.referer.RefererMiddleware',
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
'scrapy.spidermiddlewares.depth.DepthMiddleware']
2019-05-01 07:37:21 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2019-05-01 07:37:21 [scrapy.core.engine] INFO: Spider opened
2019-05-01 07:37:21 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2019-05-01 07:37:21 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2019-05-01 07:37:22 [scrapy.core.engine] DEBUG: Crawled (200) <GET http://www.ascensionsheriff.com/sheriffsale.aspx> (referer: None)
2019-05-01 07:37:22 [scrapy.core.engine] INFO: Closing spider (finished)
2019-05-01 07:37:22 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 239,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 68960,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2019, 5, 1, 11, 37, 22, 419454),
'log_count/DEBUG': 1,
'log_count/INFO': 9,
'memusage/max': 56320000,
'memusage/startup': 56320000,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2019, 5, 1, 11, 37, 21, 674444)}
2019-05-01 07:37:22 [scrapy.core.engine] INFO: Spider closed (finished)