splash 实现类似selenium的WebDriverWait

栏目: Lua · 发布时间: 6年前

内容简介:在用splash写爬虫的时候发现没有类似以freebuf为例。使用默认lua代码时经常碰到页面没有加载完全就返回源码的情况。参考了下官方文档。在lua代码中实现类似的功能。

在用splash写爬虫的时候发现没有类似 selenium的WebDriverWait 的功能。

以freebuf为例。使用默认 lua 代码时经常碰到页面没有加载完全就返回源码的情况。

参考了下官方文档。在lua代码中实现类似的功能。

在lua代码中,我们可以用 splash:select 函数来获取html的元素,因此可以通过监测某个元素是否存在来判断网页是否加载完成。当然也可以使用 splash:wait 来等待多少秒后返回源码到scrapy。

function main(splash)
    splash.images_enabled = false
    assert(splash:go(splash.args.url))
    assert(splash:wait(1))

    local el = splash:select('.icon-login')

    while not  el do
      assert(splash:wait(2))
      el = splash:select('.icon-login')
      if el then
          break
      end
    end
    assert(splash:wait(2))
    return  {splash:html(),splash:png()}
end

splash 实现类似selenium的WebDriverWait


以上所述就是小编给大家介绍的《splash 实现类似selenium的WebDriverWait》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Building Websites with Joomla!

Building Websites with Joomla!

H Graf / Packt Publishing / 2006-01-20 / USD 44.99

This book is a fast paced tutorial to creating a website using Joomla!. If you've never used Joomla!, or even any web content management system before, then this book will walk you through each step i......一起来看看 《Building Websites with Joomla!》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具