2017-09-27 20 views
0

이 이유로 스플래시 요청 끝점이 render.json에서 실행되도록 변경 되었기 때문에 iframe에서 콘텐츠를 가져 오려고합니다. Howerver, splash.wait는 전혀 작동하지 않습니다. 스파이더 코드가 있습니다.치료 종료점 = 'render.json'

import scrapy 
from scrapy_splash import SplashRequest 
from scrapy.http import HtmlResponse 
src=""" 
function main(splash, args) 
    assert(splash:go(args.url)) 
    assert(splash:wait(10)) 
    return { 
    html = splash:html() 
    } 
end 

""" 

class Lafarge (scrapy.Spider): 
    name = "lafargespider" 

    def __init__(self, *args, **kwargs): 
     self.root_url = "https://cacareers-lafarge-na.icims.com/jobs/search?pr=0&searchRelation=keyword_all&schemaId=&o=" 

    def start_requests(self): 
      yield SplashRequest(self.root_url, self.parse_detail, 
       endpoint='render.json', 
       args={ 
        'iframes': 1, 
        'html' : 1, 
        'lua_source': src, 
        'timeout': 90 
       } 
      ) 
    def parse_detail(self, response): 
     #response decoded 
     rs = response.data['childFrames'][0]['html'] 
     response = HtmlResponse(url="my HTML string", body=rs, encoding='utf-8') 
     print("next page ===>",response.xpath('//a[@class="glyph "]/@href').extract_first()) 

답변

1

Splash.request 인수에 대기 시간이 지나면 문제가 해결되었습니다.

def start_requests(self): 
     yield SplashRequest(self.root_url, self.parse_detail, 
      endpoint='render.json', 
      args={ 
       'wait': 5, 
       'iframes': 1, 
       'html' : 1, 
       'lua_source': src, 
      } 
     ) 
def parse_detail(self, response): 
    rs = response.data['childFrames'][0]['html'] 
1

args에 wait 매개 변수를 전달하십시오.

인수의 = {: 5, 'iframe을': 1, 'HTML': 1, 'lua_source': SRC, '타임 아웃'90 '대기'} -이 있어야한다