2017-12-16 19 views
0

동적으로로드 된 콘텐츠가있는 웹 페이지에서 스크래핑 문제가 발생합니다. 나는으로 시작 고정 표시기 이미지를 시작 :스플래시 스플래시 렌더링 js 페이지 관련 문제

docker run -p 8050:8050 scrapinghub/splash --disable-private-mode 
내 scrapy-시작 거미 스크롤하여 전체 페이지의 HTML 반환해야 LUA 스크립트 사용

:

import scrapy 
from scrapy_splash import SplashRequest 

class MySplashSpider(scrapy.Spider): 
    # requires the scrapy-splash docker image running 
    name = "psplash" 

    def __init__(self): 
     self.domain = 'http://www.phillips.com' 
     self.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0) Gecko/20100101 Firefox/10.0" 
     self.script = """ 
         function main(splash) 
          local num_scrolls = 3 
          local scroll_delay = 1.0 
          splash:set_viewport_full() 
          splash:wait(5.0) 
          return splash:html() 
         end 
         """ 
     self.splash_args = {'lua_source': self.script, 
          'ua': self.user_agent 
          } 

    def start_requests(self): 
     base_url = "https://www.phillips.com/auctions/past/filter/Department=20TH%20CENTURY%20%26%20CONTEMPORARY%20ART!Editions!Latin%20America!Photographs" 
     yield SplashRequest(base_url, 
          callback = self.parse_pagination, 
          endpoint = 'execute', 
          args = self.splash_args 
          )  

    def parse_pagination(self, response): 
     print('xxxxxxxxxx', response.xpath("//footer/ul/li[last()-1]/a/text()").extract()) 
     print('xxxxxxxxxx', response.xpath("//h2/a/@href").extract()) 

가 크롬 개발 도구로 확인 I

[ 
{"response_text": "hello world", "response_xpath_value": []} 
] 

콘솔 : '//footer/ul/li[last()-1]/a/text()response.xpath에 대한 어떠한 결과를 얻기없는 오전에 대해 29을 받고 있어요 출력에 오류가 표시되지 않습니다.

2017-12-16 13:05:16 [scrapy.core.engine] INFO: Spider opened 
2017-12-16 13:05:16 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 
xxxxxxxxxx [] 
xxxxxxxxxx [] 
2017-12-16 13:05:21 [scrapy.core.engine] INFO: Closing spider (finished) 
2017-12-16 13:05:21 [scrapy.statscollectors] INFO: Dumping Scrapy stats: 
{'downloader/request_bytes': 986, 
'downloader/request_count': 1, 
'downloader/request_method_count/POST': 1, 
'downloader/response_bytes': 163, 
'downloader/response_count': 1, 
'downloader/response_status_count/200': 1, 
'finish_reason': 'finished', 
'finish_time': datetime.datetime(2017, 12, 16, 12, 5, 21, 707451), 
'log_count/INFO': 7, 
'log_count/WARNING': 1, 
'response_received_count': 1, 
'scheduler/dequeued': 2, 
'scheduler/dequeued/memory': 2, 
'scheduler/enqueued': 2, 
'scheduler/enqueued/memory': 2, 
'splash/execute/request_count': 1, 
'splash/execute/response_count/200': 1, 
'start_time': datetime.datetime(2017, 12, 16, 12, 5, 16, 816927)} 
2017-12-16 13:05:21 [scrapy.core.engine] INFO: Spider closed (finished) 

여기서 내가 무엇을보고 싶습니까?

답변

0

HTML 파일에 응답 본문을 저장 한 다음 요구 사항에 따라 전체 페이지가 다운로드되는지 확인하십시오. 예인 경우 대답을 사용하십시오. selectors