【python+selenium的WebElement对象操作】教程文章相关的互联网学习教程文章

python爬虫Day2:selenium选择器

from selenium import webdriver # web驱动 from selenium.webdriver.common.keys import Keys # 键盘按键操作 import timeimport timedriver = webdriver.Chrome()try:# 隐式等待: 需要在get之前调用# 等待任意元素加载10秒driver.implicitly_wait(10)driver.get(https://www.baidu.com/)# 显式等待: 需要在get之后调用time.sleep(5)===============所有方法===================element是查找一个标签elements是查找所有标签# 自...

python selenium webdriver:使用authenticate方法【代码】

我使用python selenium webdriver来自动化检查.我被困在通过弹出窗口请求http身份验证的网站上. 我试图通过以下代码使用“authenticate”方法:#init. driver = webdriver.Firefox() driver.get(url) #get to the auth popup window by clicking relevant link elem = driver.find_element_by_id("login_link") elem.click() #use authenticate alert method driver._switch_to.alert.authenticate("login", "password")与此方法相...

Python Selenium chromedriver OSError:[Errno 8] Exec格式错误【代码】

我正试图在我的python(2.7)脚本中设置与Selenium的chrome会话,如下所示:from selenium import webdriver driver=webdriver.Chrome()但是我收到以下错误:Traceback (most recent call last): File "soup_test.py", line 30, in <module> driver=webdriver.Chrome() File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__ self.service.start() File "/usr/local/lib/pyth...

模仿通过Python中的Selenium使用的PhantomJS上的HTML5视频支持【代码】

我正在尝试提取视频标记中的HTML5视频的源链接.使用Firefox webdrive,我能够获得所需的结果,即 – [<video class="video-stream html5-main-video" src='myvideoURL..'</video>]但如果我使用PhantomJS – <video class="video-stream html5-main-video" style="width: 854px; height: 480px; left: 0px; top: 0px; -webkit-transform: none;" tabindex="-1"></video>我怀疑这是因为PhantomJS缺乏HTML5视频支持.反正我是否可以欺骗...

python – Selenium – ElementNotVisibleException【代码】

我在selenium的这个ElementNotVisibleException问题上看到了很多问题/答案.我到目前为止所做的最好的代码如下:from selenium.webdriver.support.ui import WebDriverWait from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC url = "http://...

Selenium / Python:JavaScript href拒绝执行【代码】

所以,我在Python 3.5上运行Selenium,尝试单击一个带有JavaScript函数的按钮作为其href.我尝试过帮助他人的解决方案,但我的问题不会让步. 版本库存: >硒3.0.2> Anaconda 4.1.1上的Python 3.5.2> Firefox 51.0.1 按钮的html如下:<tbody><tr><td><a href='JavaScript:SWESubmitForm(document.SWEForm11_0,c_45,"s_11_1_0_0","")' tabindex="1700">Choose Account</a></td></tr><tr><td>View a different account</td></tr> </tbody>...

Python / Selenium:如何使用无头Chrome驱动程序模拟uBlock或AdBlock等扩展程序?【代码】

我在Python中使用Selenium / ChromeDriver.在我的代码中使用ChromeDriver选项:options = webdriver.ChromeOptions() options.add_argument('headless') options.add_argument('load-extension=' +uBlockExtensionPATH) browser = webdriver.Chrome(chrome_options=options)但是,无头Chrome不支持按照此answer使用扩展程序.我能够让无头Chrome使用我当前的Python脚本,一切正常,但由于第三方广告需要很长时间才能访问网站/分析/请求...

Python Selenium等待用户单击按钮【代码】

语境: >我的脚本使用selenium webdriver启动到网站>用户填写网站上的一些东西>用户将点击一个按钮,弹出确认()dialogbox询问用户“你想提交数据吗” 我的本意: 我的脚本会等到用户点击按钮.一旦检测到用户点击了该按钮,我的脚本就会获得一个元素的值,然后(不知何故)在dialog box上单击OK. 题: 如何等待用户点击按钮? 然后如何在dialog box上单击“确定”? 补充说明: 使用:chromedriver,Python 2.7 按钮:< input id =“submi...

Python_selenium之获取当前页面的href属性,id属性,图片信息和截全屏

一、 获取当前页面的全部信息 1. 图片信息包括图片名称、图片大小等信息 2. 只需将图片信息打印出来(image.text image.size image.tag_name) 二、 获取页面元素的href属性(id同理) 1. 获取当前页面所有的链接信息(以百度首页为例) 2. 运用for循环,然后运用get_attribute(‘href’) 3. 然后将之打印出来即可 三、 截取全屏信息 1. 运用get_screenshot_file()进行截图即可 四、 测试脚本 1. 将以上三种代码写在一起,...

如何通过Selenium WebDriver和Python找到用户名和密码元素【代码】

我正在尝试使用Selenium自动输入特定网站的用户名和密码.我无法找到要发送密钥的元素.我在下面附上了网站的HTML代码. 这是我目前使用的:username = driver.find_element_by_id('UserName').getAttribute('value')此外,网站以.bsd结尾,我并不完全熟悉它,并认为它可能导致问题. 谢谢.<html><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"><link rel="stylesheet" href="css/general.css" type="text/c...

Python Scrapy Selenium整合:启动浏览器并登陆

某些网站要求用户必须先登录,然后才能获取网络数据,这样爬虫程序将无法随意爬取数据。 为了登录该网站,通常有两种做法: 直接用爬虫程序向网站的登录处理程序提交请求,将用户名、密码、验证码等作为请求参数,登录成功后记录登录后的 Cookie 数据。 使用真正的浏览器来模拟登录,然后记录浏览器登录之后的 Cookie 数据。上面两种方式的目的是一样的,都是为了登录目标网站,记录登录后的 Cookie 数据。但这两种方式各有优缺点:...

如何在Selenium Python中编写功能/集成测试【代码】

我是新手测试,我想 1)测试登录 2)创建一个文件夹 3)将内容(页面)添加到文件夹中 我已经编写了每个测试并且它们工作但显然我想建立彼此的ontop,例如,为了做3我需要做1然后2.为了做2我需要做1.这是我的基本测试结构:class TestSelenium(unittest.TestCase):def setUp(self):# Create a new instance of the Firefox driverself.driver = webdriver.Firefox()def testLogin(self):print '1'...def testFolderCreation(self):print '2...

如何使用Selenium [在Python中]导入Firefox的SSL证书?【代码】

尝试使用Python WebDriver和FirefoxProfile找到一种使用Selenium在Firefox中安装特定SSL证书的方法.我们需要使用我们自己的自定义证书,该证书存储在运行WebDriver的计算机中,因此理想的解决方案如下所示:profile = get_my_profile() profile.importCertificate('/my/certificates/my_cert.cert') driver = new webdriver.Firefox(profile=profile)我怎样才能做到这一点? 非常感谢!解决方法:From this answerWebdriver has no bu...

Selenium-python下载但文件保存为.part【代码】

我的脚本可以工作,但它将文件保存为.part,尽管对手动下载的文件检查它的大小相同,谢天谢地完成.我无法理解为什么它被保存为部分文件. Sorta不便于我的下一个想法.有没有人知道为什么会这样?这是我的代码……哪个有效……from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys import time import mechanize import urllib from urllib...

python – selenium webdriver.Firefox无法启动非sudo用户【代码】

我有一个python方法,在Linux服务器上以无头模式设置浏览器,用于使用selenium进行网站抓取.无论哪个用户执行python脚本,显示器都能完全正常设置,但如果sudo用户没有执行脚本,它将无限期挂在webdriver.Firefox()设置行. 这是完整的方法:def browserSetup(self, browser=None):try:# now Firefox will run in a virtual display. you will not see the browser. self.display = Display(visible=0, size=(800, 600))self.display.st...