内容简介:在用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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 类似Github的webhook实现
- ASP实现类似hashMap功能的类
- PHP实现类似题库抽题效果
- java实现golang类似的chan
- C++ 中类似 Python 的 dict 的实现
- 如何实现类似 lodash 的 get 与 merge 函数
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
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!》 这本书的介绍吧!