Python动态网页爬虫技巧Selenium(一)
2018-02-08 17:34
597 查看
implicitly_wait() 跟 WebdriverWait()的区别
相同点:这两个东西,都是为了在测试网页的时候进行等待的
一方面是都可以完成对于动态数据的等待和爬取。(都是一旦完成就直接溜掉~)
不同点:
前者是隐式等待,后者是显式等待。可能有人要问区别了。区别很简单。implicityly_wait()只需要使用一次,之后关于这个DOM文档树(好像是这个中文),中的任何一个元素,都会有这样的一个隐式等待。但是对于后者,就是每次使用的时候都需要自己再设置一次时间。
后者使用更为灵活一些,可以配合selenium自身的很多库来进行设置,前者就比较简单,如果没有什么特别的要求的话,用前面的那种就可以了~
下面也展示两者的使用方法:
隐式from selenium import webdriver if __name__ == '__main__': dr = webdriver.Chrome() dr.get("http://www.baidu.com") dr.implicitly_wait(10) # 这里~ element = dr.find_element_by_id("su") print(element) dr.quit() pass
显式(配合多种库一起用,更灵活,也更麻烦)
from selenium import webdriver from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait if __name__ == '__main__': dr = webdriver.Chrome() dr.get("http://www.baidu.com") wait = WebDriverWait(dr, 10) # 设置某个空间等待10秒这个事件 element = wait.until(EC.element_to_be_clickable((By.ID, "su"))) # 直到检测到某个事件前一直等待 print(element) dr.quit() pass
相关文章推荐
- python爬虫selenium+firefox抓取动态网页--表情包爬虫实战
- python+Selenium2+chrome构建动态网页爬虫工具
- python /selenium /动态网页 /爬虫
- Python爬虫学习——使用selenium和phantomjs爬取js动态加载的网页
- python+Selenium2+chrome构建动态网页爬虫工具
- Python爬虫(入门+进阶)学习笔记 1-8 使用自动化神器Selenium爬取动态网页(案例三:爬取淘宝商品)
- python+Selenium2+chrome构建动态网页爬虫工具
- 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求
- python+Selenium2+chrome构建动态网页爬虫工具
- [Python爬虫]Scrapy配合Selenium和PhantomJS爬取动态网页
- 关于我的第一个爬虫--Python+selenium+parsel+动态网页
- Python 爬虫修养-处理动态网页
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
- Python爬虫实战(动态网页)
- 用python+selenium+firefox爬取动态网页
- 使用Python+selenium+BeautifulSoup抓取动态网页的关键信息
- Python爬虫实战--(三)获取网页中的动态数据
- 基于Python3的phantomJs+Selenium动态网页爬取技术
- Python selenium爬虫抓取船舶网站数据(动态页面)
- Python3网络爬虫:requests爬取动态网页内容