我正在关注此link,我能够成功运行一个basespider。
当我尝试使用与crawlspider相同的时候,我没有得到任何输出。
我的蜘蛛如下:
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.http import request
from scrapy.selector import HtmlXPathSelector
from medsynergies.items import MedsynergiesItem
class medsynergiesspider(CrawlSpider):
name="medsynergies"
allowed_domains=['msi-openhire.silkroad.com/epostings/']
start_urls=['https://msi-openhire.silkroad.com/epostings/index.cfm?fuseaction=app.jobsearch']
rules=(
Rule(SgmlLinkExtractor(allow=("jobsearch",))),
Rule(SgmlLinkExtractor(allow=("jobinfo&jobid",)),callback="parse_job",follow=True),
)
def parse_job(self, response):
hxs=HtmlXPathSelector(response)
titles=hxs.select('//*[@id="jobDesciptionDiv"]')
items = []
for titles in titles:
item=MedsynergiesItem()
item['job_id']=response.url
item['title']=titles.select('normalize-space(//*[@id="jobTitleDiv"]/text())').extract()
item['tracking_code']=titles.select('normalize-space(//*[@id="trackCodeDiv"]/text())').extract()
item['job_description']=titles.select('.//p/text()').extract()
item['responsibilities']=titles.select('.//ul/li/text()').extract()
item['required_skills']=titles.select('normalize-space(//*[@id="jobRequiredSkillsDiv"]/ul)').extract()
item['job_location']=titles.select('normalize-space(//*[@id="jobPositionLocationDiv"]/text())').extract()
item['position_type']=titles.select('normalize-space(//*[@id="translatedJobPostingTypeDiv"]/text())').extract()
items.append(item)
print items
return items
我得到的输出如下:
abhishek@abhishek-VirtualBox:~/projects/medsynergies$ scrapy crawl medsynergies > output.txt
2014-02-24 17:18:07-0700 [scrapy] INFO: Scrapy 0.22.1 started (bot: medsynergies)
2014-02-24 17:18:07-0700 [scrapy] INFO: Optional features available: ssl, http11, boto, django
2014-02-24 17:18:07-0700 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'medsynergies.spiders', 'SPIDER_MODULES': ['medsynergies.spiders'], 'BOT_NAME': 'medsynergies'}
2014-02-24 17:18:07-0700 [scrapy] INFO: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, SpiderState
2014-02-24 17:18:07-0700 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats
2014-02-24 17:18:07-0700 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2014-02-24 17:18:07-0700 [scrapy] INFO: Enabled item pipelines:
2014-02-24 17:18:07-0700 [medsynergies] INFO: Spider opened
2014-02-24 17:18:07-0700 [medsynergies] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2014-02-24 17:18:07-0700 [scrapy] DEBUG: Telnet console listening on 0.0.0.0:6023
2014-02-24 17:18:07-0700 [scrapy] DEBUG: Web service listening on 0.0.0.0:6080
2014-02-24 17:18:16-0700 [medsynergies] DEBUG: Crawled (200) <GET https://msi-openhire.silkroad.com/epostings/index.cfm?fuseaction=app.jobinfo&jobid=1284&source=ONLINE&JobOwner=992700&company_id=16616&version=1&byBusinessUnit=NULL&bycountry=0&bystate=0&byRegion=&bylocation=NULL&keywords=&byCat=NULL&proximityCountry=&postalCode=&radiusDistance=&isKilometers=&tosearch=yes> (referer: None) ['partial']
2014-02-24 17:18:16-0700 [medsynergies] INFO: Closing spider (finished)
2014-02-24 17:18:16-0700 [medsynergies] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 496,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 6637,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2014, 2, 25, 0, 18, 16, 171093),
'log_count/DEBUG': 3,
'log_count/INFO': 7,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2014, 2, 25, 0, 18, 7, 451729)}
2014-02-24 17:18:16-0700 [medsynergies] INFO: Spider closed (finished)
请让我知道我在做错的地方。如果我的规则过于严格,我如何更改它们以便刮掉它们?