@Vlad_beg

Почему при парсинге нескольких страниц выдает ошибку 504 Gateway Time-out?

Необходимо спарсить несколько страниц с сайта, при парсинге 1-2 страниц все работает прекрасно, если указываю 5 вылетает ошибка

504 Gateway Time-out

и в итоге возвращается пустой результат
Вот код парсера
script = '''
    function main(splash, args)
      assert(splash:go(args.url))
      assert(splash:wait(5.0))
      treat=require('treat')
      result = {}
      pages = splash:select('.shopee-mini-page-controller__total')

      for i=1,5,1 do
        for j=1,2,1 do
          assert(splash:runjs("window.scrollBy(0, 1300)"))
          assert(splash:wait(1.0))
        end

        result[i]=splash:html()
        assert(splash:runjs('document.querySelector(".shopee-icon-button--right").click()'))
        assert(splash:wait(5.0))
      end
      return treat.as_array(result)
    end
  '''

  def start_requests(self):
    urls = [
        'https://shopee.sg/search?keyword=hdmi'
    ]
    for link in urls:
      yield SplashRequest(url=link, callback=self.parse, endpoint='execute', args={'wait': 1.5, 'lua_source' : self.script}, dont_filter=True)

  def parse(self, response):
    for page in response.data:
      sel = Selector(text=page)

      yield {
        'urls': sel.xpath("//div[contains(@class, 'shopee-search-item-result__item')]//a[*]/@href").getall()
      }
  • Вопрос задан
  • 364 просмотра
Пригласить эксперта
Ответы на вопрос 1
@Verz1Lka
Web scraping expert
Вообще, 504 от splash приходит, когда он не успевает выполнить код (максимумальный таймаут выполенения по умолчанию 30сек).
Почитайте этот раздел, может поможет: https://splash.readthedocs.io/en/stable/faq.html#t...
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы