嗨,当我运行Spider时,我无法在控制台中看到任何报废的数据。 这是我的蜘蛛。
import scrapy
class HackaholicSpider(scrapy.Spider):
name = "hackaholic"
def start_request(self):
urls = ['http://hackaholic.info']
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
for article in response.xpath('//article'):
yield {
'title': article.xpath("//h2[@class='entry-title']/a/text()").extract(),
'published_date': article.xpath("//div[@class='entry-meta']/span/time[@class='onDate date published']/a/text()").extract()
}
我正在尝试提取文章标题和发布日期。
当我跑蜘蛛时:
juniour@hackaholic:~/git/scrapy/tutorial$ scrapy crawl hackaholic
2018-09-27 17:43:07 [scrapy.utils.log] INFO: Scrapy 1.5.1 started (bot: tutorial)
2018-09-27 17:43:07 [scrapy.utils.log] INFO: Versions: lxml 4.2.1.0, libxml2 2.9.4, cssselect 1.0.3, parsel 1.5.0, w3lib 1.19.0, Twisted 18.7.0, Python 3.6.6 (default, Sep 12 2018, 18:26:19) - [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]], pyOpenSSL 17.5.0 (OpenSSL 1.1.0g 2 Nov 2017), cryptography 2.1.4, Platform Linux-4.15.0-34-generic-x86_64-with-Ubuntu-18.04-bionic
2018-09-27 17:43:07 [scrapy.crawler] INFO: Overridden settings: {'BOT_NAME': 'tutorial', 'NEWSPIDER_MODULE': 'tutorial.spiders', 'ROBOTSTXT_OBEY': True, 'SPIDER_MODULES': ['tutorial.spiders']}
2018-09-27 17:43:07 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.logstats.LogStats']
2018-09-27 17:43:07 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
'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']
2018-09-27 17:43:07 [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']
2018-09-27 17:43:07 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-09-27 17:43:07 [scrapy.core.engine] INFO: Spider opened
2018-09-27 17:43:07 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2018-09-27 17:43:07 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6024
2018-09-27 17:43:07 [scrapy.core.engine] INFO: Closing spider (finished)
2018-09-27 17:43:07 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'finish_reason': 'finished',
'finish_time': datetime.datetime(2018, 9, 27, 12, 13, 7, 699046),
'log_count/DEBUG': 1,
'log_count/INFO': 7,
'memusage/max': 51904512,
'memusage/startup': 51904512,
'start_time': datetime.datetime(2018, 9, 27, 12, 13, 7, 696301)}
2018-09-27 17:43:07 [scrapy.core.engine] INFO: Spider closed (finished)
答案 0 :(得分:1)
您必须将<select id="selectProjectName" class="form-control show-tick selectpicker" title="Choose project name">
</select>
方法重命名为start_request
,这是您必须从基类start_requests
覆盖的方法。更多信息here。
正在发生的事情是,由于缺少Spider
方法,您的蜘蛛没有发出任何请求。
这应该是这样的:
start_requests