【问题标题】:Scrapy Splash HTTP status code is not handled or not allowedScrapy Splash HTTP 状态码未处理或不允许
【发布时间】:2021-05-13 13:06:40
【问题描述】:

我正在使用 scrapy-splash 抓取使用 javascript 加载结果的汽车经销商网站,但我不断收到错误 504 Gateway Time-out。

我有 docker 和 Win10,我认为问题不是 docker 配置,因为我可以使用相同的代码抓取另一个站点。

import scrapy
from scrapy_splash import SplashRequest
from scrapy.loader import ItemLoader
from ..items import  AutoItem

class Main_Spider(scrapy.Spider):
     name = 'dealers'
     allowed_domains = ['audidowntowntoronto.com']
         
     script = '''
     function main(splash)
        local scroll_delay = 3
        local is_down = splash:jsfunc("function() { return((window.innerHeight + window.scrollY) >= document.body.offsetHeight);}")
        local scroll_to = splash:jsfunc("window.scrollTo")
        local get_body_height = splash:jsfunc("function() {return document.body.scrollHeight;}")
        assert(splash:go(splash.args.url))
        while not is_down() do
            scroll_to(0, get_body_height())
            splash:wait(scroll_delay)
        end        
        return splash:html()
     end
     '''
     
     def start_requests(self):    
       yield SplashRequest(url="http://audidowntowntoronto.com/all/", callback=self.parse, endpoint="execute", args={'lua_source': self.script})

     def parse(self, response):      
        url = response.xpath('//*[@itemprop="url"]/@href').extract() 
        print (url)

【问题讨论】:

    标签: python scrapy scrapy-splash scrapyd


    【解决方案1】:

    这里不用lua脚本也没关系。添加如下所示的端点和其他参数。

    yield SplashRequest(
                        url="http://audidowntowntoronto.com/all/",
                        callback=self.parse,
                        args={
                                'html': 1,
                                'wait': 5,
                                'render_all': 1
                            },
                        endpoint='render.json')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多