webdriver

web自动化的三大等待

橙三吉。 提交于 2020-02-15 18:47:02
由于web网页打开后需要时间进行数据的传送,页面的渲染,所以我们在写web自动化脚本的时候,需要等待它加载完所有的页面元素,我们才进行操作或点击。同时这种等待也是为了提高脚本的稳定性。 selenium中有三种等待,分别是强制等待,隐性等待和显性等待: 1、强制等待 不管浏览器是否加载完,程序都要等待设置的时间,不建议经常使用该等待方式,会严重影响程序的执行速度。 time.sleep(秒数)-----这里的时间单位是秒,表示强制等待几秒 在使用该函数前要导入time模块 import time from selenium import webdriver driver = webdriver.Chrome() driver.get("http://ke.qq.com") time.sleep(3) 2、隐性等待 隐形等待是设置了一个最长等待时间,如果在规定时间内网页加载完成,则执行下一步,否则一直等到时间截止,然后执行下一步。注意这里有一个弊端,那就是程序会一直等待整个页面加载完成。隐性等待对driver的整个周期都起作用,所以只要设置一次即可。 implicitly_wait(30)----隐性等待,最长时长为30秒 from selenium import webdriver driver = webdriver.Chrome() driver.get("http://ke

What is the difference between build().perform() and perform()

╄→尐↘猪︶ㄣ 提交于 2020-02-15 06:48:12
问题 Some articles suggest that now build() is included in perform() itself, while others suggest that build().perform() is used when multiple actions are to be chained together. 回答1: build() is included in perform() , you can see it in the source code public void perform() { build().perform(); } The perform() inside the methods calls the perform() method in the inner class BuiltAction . Calling build().perform() in your code is actually calling build() twice, build().build().perform() . build

What is the difference between build().perform() and perform()

爱⌒轻易说出口 提交于 2020-02-15 06:47:29
问题 Some articles suggest that now build() is included in perform() itself, while others suggest that build().perform() is used when multiple actions are to be chained together. 回答1: build() is included in perform() , you can see it in the source code public void perform() { build().perform(); } The perform() inside the methods calls the perform() method in the inner class BuiltAction . Calling build().perform() in your code is actually calling build() twice, build().build().perform() . build

What is the difference between WebDriver and WebElement in Selenium?

纵然是瞬间 提交于 2020-02-15 06:43:21
问题 What is the difference between WebDriver and WebElement in Selenium? Sample Code: WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); WebElement s = driver.findElement(By.name("q")); s.sendKeys("Packt Publishing"); s.submit(); 回答1: WebDriver Interface From Selenium's perspective, the What is the difference between ChromeDriver and WebDriver in selenium? interface is similar like a agreement which the 3rd party Browser Vendors like Mozilla , Chrome , Internet Explorer

What is the difference between WebDriver and WebElement in Selenium?

坚强是说给别人听的谎言 提交于 2020-02-15 06:43:17
问题 What is the difference between WebDriver and WebElement in Selenium? Sample Code: WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); WebElement s = driver.findElement(By.name("q")); s.sendKeys("Packt Publishing"); s.submit(); 回答1: WebDriver Interface From Selenium's perspective, the What is the difference between ChromeDriver and WebDriver in selenium? interface is similar like a agreement which the 3rd party Browser Vendors like Mozilla , Chrome , Internet Explorer

Sign in to gmail account fails (selenium automation)

倖福魔咒の 提交于 2020-02-13 22:26:59
问题 I have a Selenium service that has to login to my gmail account as the first step. This functionality was working couple of weeks ago, but suddenly the login starts to fails and i am seeing this Error in browser, tried both in Chrome and Firefox drivers in selenium - This Error comes after the selenium service inserts the email,password and clicks on the sign in button. A similar error was also reported in Google support Forum here- https://support.google.com/accounts/thread/10916318?hl=en,

30分钟编写一个抓取 Unsplash 图片的 Python爬虫

℡╲_俬逩灬. 提交于 2020-02-13 20:26:03
我一直想用 Python and Selenium 创建一个网页爬虫,但从来没有实现它。 几天前, 我决定尝试一下,这听起来可能是挺复杂的, 然而编写代码从 Unsplash 抓取一些美丽的图片还是挺容易的。 PS:很多人在学习Python的过程中,往往因为遇问题解决不了或者没好的教程从而导致自己放弃,为此我整理啦从基础的python脚本到web开发、爬虫、django、数据挖掘等【PDF等】需要的可以进Python全栈开发交流.裙 :一久武其而而流一思(数字的谐音)转换下可以找到了,里面有最新Python教程项目可拿,不懂的问题有老司机解决哦,一起相互监督共同进步! 简易图片爬虫的组成部分 Python (3.6.3 或者更新版本) Pycharm (Community edition 版本就可以) Requests Pillow Selenium Geckodriver (阅读下面的说明) Mozlla Firefox (如果你没有,去安装一下) 有效的网络连接 (显而易见的) 你的 30 分钟 (可能更少) 简易图片爬虫的制作 把所有东西都安装好了么?不错!跟着我们的代码,我将开始解释我们每一个爬虫原料的作用。 第一件事情,我们将 把 Selenium webdriver 和 geckodriver 结合起来去打开一个为我们工作的浏览器窗口。首先,在 Pycharm

python爬虫——使用chrome的无界面浏览器options(豆瓣下拉滚动条)

狂风中的少年 提交于 2020-02-12 12:44:44
一.概述 1. 2.安装chromedriver 上一篇文章写过,点击即可查看 二.简单操作 案例一: from selenium import webdriver from selenium . webdriver . chrome . options import Options import time # chromedriver.exe路径 path = r 'E:\chromedriver_win32\chromedriver.exe' # 创建chrome浏览器驱动,无头模式) chrome_options = Options ( ) chrome_options . add_argument ( '--headless' ) browser = webdriver . Chrome ( executable_path = path , options = chrome_options ) # 打开百度 url = 'http://www.baidu.com/' browser . get ( url ) time . sleep ( 3 ) # 截图并保存 browser . save_screenshot ( 'baidu.png' ) # 打印页面标题 "百度一下,你就知道" print ( browser . title ) # 关闭浏览器 browser .

requests从selenium获取cookies

我是研究僧i 提交于 2020-02-12 11:51:35
1 # coding:utf-8 2 # 用webdriver登录并获取cookies,并用requests发送请求,以豆瓣为例 3 from selenium import webdriver 4 import requests 5 import time 6 import json 7 import sys 8 reload(sys) 9 sys.setdefaultencoding('utf-8') 10 11 def main(): 12 # 从命令行参数获取登录用户名和密码 13 user_name = sys.argv[1] 14 password = sys.argv[2] 15 16 # 豆瓣登录页面URL 17 login_url = 'https://www.douban.com/accounts/login' 18 19 # 获取chrome的配置 20 opt = webdriver.ChromeOptions() 21 # 在运行的时候不弹出浏览器窗口 22 # opt.set_headless() 23 24 # 获取driver对象 25 driver = webdriver.Chrome(chrome_options = opt) 26 # 打开登录页面 27 driver.get(login_url) 28 29 print 'opened

Selenium之元素定位

痴心易碎 提交于 2020-02-12 11:47:29
1.查看页面元素:ID、class、type、name等。 2.通过webdriver的方法定位: find_element_by_name() find_element_by_id() find_element_by_class_name() browser.find_element_by_xpath(); 绝对路径:find_element_by_xpath("/html/body/div[1]/div[1]/div/div[1]/div/form/span[1]/input") 相对路径: find_element_by_xpath("//input[@id='kw']") find_element_by_xpath("//*[@name='wd']") find_element_by_css_selector() 一般class是用.标记,id是用#标记,标签名直接写具体标签名就好了 find_element_by_link_text() find_element_by_partial_link_text() 3.通过By定位: find_element(By.ID,"kw") find_element(By.NAME,"wd") find_element(By.CLASS_NAME,"s_ipt") find_element(By.TAG_NAME,"input")