如何确保scrapy splash成功渲染了整个页面

如何确保scrapy splash成功渲染了整个页面,scrapy,scrapy-spider,splash-screen,scrapy-splash,splash-js-render,Scrapy,Scrapy Spider,Splash Screen,Scrapy Splash,Splash Js Render,当我通过使用splash呈现整个目标页面来爬网整个网站时,出现了问题。某些页面不是随机成功的,因此当呈现作业完成时,我获取支持存在的信息是错误的。这意味着我仅从呈现结果中获取部分信息,尽管我可以从中获取全部信息其他渲染结果 这是我的密码: yield SplashRequest(url,self.splash_parse,args = {"wait": 3,},endpoint="render.html") settings: SPLASH_URL = 'XXX' DOWNLOADER_M

当我通过使用splash呈现整个目标页面来爬网整个网站时,出现了问题。某些页面不是随机成功的,因此当呈现作业完成时,我获取支持存在的信息是错误的。这意味着我仅从呈现结果中获取部分信息,尽管我可以从中获取全部信息其他渲染结果

这是我的密码:

yield SplashRequest(url,self.splash_parse,args = {"wait": 3,},endpoint="render.html")

settings:
SPLASH_URL = 'XXX'  
DOWNLOADER_MIDDLEWARES = {
'scrapy_splash.SplashCookiesMiddleware': 723,
'scrapy_splash.SplashMiddleware': 725,
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
}

# Enable SplashDeduplicateArgsMiddleware:
SPIDER_MIDDLEWARES = {
'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}

# Set a custom DUPEFILTER_CLASS:
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter

# a custom cache storage backend:
HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage'

我这么晚才回复,因为这个问题没有答案,而且在谷歌搜索上也可以看到

我也遇到过类似的问题,我找到的唯一解决方案(除了增加
wait
参数,该参数可能有效,也可能无效,但不可靠)是使用
execute
端点和自定义lua脚本来等待元素。如果这听起来不必要的复杂,是的,在我看来,刮擦和飞溅不是很好的设计,但我还没有找到更好的我的需要

我的Lua脚本如下所示:

lua_base = '''
function main(splash)
  splash:init_cookies(splash.args.cookies)
  splash:go(splash.args.url)

  while not splash:select("{}") do
    splash:wait(0.1)
  end
  splash:wait(0.1)
  return {{
  cookies = splash:get_cookies(),
  html=splash:html()
  }}
end
'''
css = 'table > tr > td.mydata'
lua_script = lua_base.format(css)
        yield SplashRequest(link, self.parse, endpoint='execute',
                            args={
                                    'wait': 0.1,
                                    'images': 0,
                                    'lua_source': lua_script,
                                })
我生成如下请求:

lua_base = '''
function main(splash)
  splash:init_cookies(splash.args.cookies)
  splash:go(splash.args.url)

  while not splash:select("{}") do
    splash:wait(0.1)
  end
  splash:wait(0.1)
  return {{
  cookies = splash:get_cookies(),
  html=splash:html()
  }}
end
'''
css = 'table > tr > td.mydata'
lua_script = lua_base.format(css)
        yield SplashRequest(link, self.parse, endpoint='execute',
                            args={
                                    'wait': 0.1,
                                    'images': 0,
                                    'lua_source': lua_script,
                                })

这很难看,但很管用。

所以你得到了你的数据,但不是全部?尝试增加等待参数。