2017-11-18 12 views
0

나는 아주 간단한 Scrapy + Splash 프로젝트를 개발하여 자바 스크립트 웹 사이트를 크롤링합니다. 이건 내 코드입니다 :매우 간단한 치료 + 스플래쉬 프로젝트

splashtest.py :

import scrapy 
from scrapy_splash import SplashRequest 

class SplashSpider(scrapy.Spider): 
    name = 'splash_spider' 

    def start_requests(self): 
     yield SplashRequest(
      url='http://aszx.altervista.org/scrapytest/test.html', 
      callback=self.parse, 
     ) 

    def parse(self, response): 
     self.log('I have just visited ' + response.url) 
     for squadre in response.css('#hello'): 
      yield { 
       'name': squadre.css('::text').extract_first(), 
      } 

settings.py : 그래서

# scrapy runspider splashtest.py 
2017-11-18 10:10:21 [scrapy] INFO: Scrapy 1.0.5.post4+g4b324a8 started (bot: scrapybot) 
2017-11-18 10:10:21 [scrapy] INFO: Optional features available: ssl, http11 
2017-11-18 10:10:21 [scrapy] INFO: Overridden settings: {} 
2017-11-18 10:10:21 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState 
2017-11-18 10:10:22 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats 
2017-11-18 10:10:22 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware 
2017-11-18 10:10:22 [scrapy] INFO: Enabled item pipelines: 
2017-11-18 10:10:22 [scrapy] INFO: Spider opened 
2017-11-18 10:10:22 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 
2017-11-18 10:10:22 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023 
2017-11-18 10:10:22 [scrapy] DEBUG: Crawled (200) <GET http://aszx.altervista.org/scrapytest/test.html> (referer: None) 
2017-11-18 10:10:22 [splash_spider] DEBUG: I have just visited http://aszx.altervista.org/scrapytest/test.html 
2017-11-18 10:10:22 [scrapy] DEBUG: Scraped from <200 http://aszx.altervista.org/scrapytest/test.html> 
{'name': u'No Javascript'} 
2017-11-18 10:10:22 [scrapy] INFO: Closing spider (finished) 
2017-11-18 10:10:22 [scrapy] INFO: Dumping Scrapy stats: 
{'downloader/request_bytes': 252, 
'downloader/request_count': 1, 
'downloader/request_method_count/GET': 1, 
'downloader/response_bytes': 392, 
'downloader/response_count': 1, 
'downloader/response_status_count/200': 1, 
'finish_reason': 'finished', 
'finish_time': datetime.datetime(2017, 11, 18, 9, 10, 22, 975769), 
'item_scraped_count': 1, 
'log_count/DEBUG': 4, 
'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(2017, 11, 18, 9, 10, 22, 469984)} 
2017-11-18 10:10:22 [scrapy] INFO: Spider closed (finished) 

나는 돈이 내 반응이다

BOT_NAME = 'emybet' 

SPIDER_MODULES = ['emybet.spiders'] 
NEWSPIDER_MODULE = 'emybet.spiders' 

SPLASH_URL = 'http://localhost:8050' 
DOWNLOADER_MIDDLEWARES = { 
    'scrapy_splash.SplashCookiesMiddleware': 723, 
    'scrapy_splash.SplashMiddleware': 725, 
    'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810, 
} 
SPIDER_MIDDLEWARES = { 
    'scrapy_splash.SplashDeduplicateArgsMiddleware': 100, 
} 
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter' 

HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage' 

자바 스크립트 로딩 된 컨텐츠를 얻지 못한다. 브라우저를 http://localhost:8050으로 지정하면 Splash 페이지가 표시되므로 Splash가 실행 중입니다.

그래서 문제가 무엇입니까? "scrapy의 startproject 이름"하지만 난 폴더 및 파일 자신을 만든 :

감사

답변

0

문제는 내가 COMAND와 scrapy 프로젝트를 시작하지 않은 것입니다.

+1

그래, 네가 스스로 생성하는 경우 네이밍 컨 비언 스를 잡아야합니다 (예 : 거미를 복사 할 때). Afaik, 클래스 이름이 SplashSpider 였기 때문에 이름은 'splash' –