splinter

Sending Keys Using Splinter

╄→尐↘猪︶ㄣ 提交于 2020-08-22 05:36:47
问题 I want to test an autocomplete box using Splinter. I need to send the 'down' and 'enter' keys through to the browser but I'm having trouble doing this. I am currently finding an input box and typing 'tes' into that box successfully context.browser.find_by_xpath(\\some\xpath\).first.type('tes') What I want to do next is to send some keys to the browser, specifically the 'down' key (to select the first autocomplete suggestion) then send the 'enter' key to select that autocomplete element. I've

python splinter 小坑说明

孤人 提交于 2020-07-29 05:10:31
__testUrl = browser = Browser() browser.visit(__testUrl) res = + browser.title (res) : browser.find_by_id().fill() obj = browser.find_by_id().click() res = browser.html (, ).write(res) Exception,x: print (x) CLOASE_AFTER_TEST: browser.quit() 来源: oschina 链接: https://my.oschina.net/u/4399511/blog/4317437

简单的Python 火车抢票程序

烂漫一生 提交于 2020-04-28 22:24:48
当你想查询一下火车票信息的时候,你还在上12306官网吗?或是打开你手机里的APP?下面让我们来用Python写一个命令行版的火车票查看器, 只要在命令行敲一行命令就能获得你想要的火车票信息!如果你刚掌握了Python基础,这将是个不错的小练习。 接口设计 一个应用写出来最终是要给人使用的,哪怕只是给你自己使用。所以,首先应该想想你希望怎么使用它?让我们先给这个小应用起个名字吧,既然及查询票务信息,那就叫它tickets好了。我们希望用户只要输入出发站,到达站以及日期就让就能获得想要的信息,所以tickets应该这样被使用: $ tickets from to date 另外,火车有各种类型,高铁、动车、特快、快速和直达,我们希望可以提供选项只查询特定的一种或几种的火车,所以,我们应该有下面这些选项: -g 高铁 -d 动车 -t 特快 -k 快速 -z 直达 这几个选项应该能被组合使用,所以,最终我们的接口应该是这个样子的: $ tickets [-gdtkz] from to date 接口已经确定好了,剩下的就是实现它了。 开发环境 写Python程序的一个良好实践是使用virtualenv这个工具建一个虚拟的环境。我们的程序使用Python3开发,下面在你的工作目录下建一个文件夹tickets,进去创建一个虚拟环境: $ virtualenv -p /usr/bin

(转)Python控制浏览器,自动获取网页数据

主宰稳场 提交于 2020-04-27 03:01:44
【新手任务】 老板:我们做海外市场的,搞定投资商很重要。你去把境外投资企业(机构)全部给我复制下来。 任务.png 总共2606页,点下一页,然后再ctrl+C,然后Ctrl+V,准备着复制到天亮吧。扫视一圈,新来的实习生都回学校做毕业论文了。 【解决方案】 知识点: Python 3 基本语法,splinter库和xpath基本知识 Case 1: python利用splinter库,控制chrome浏览器,打开网页,获取数据。抓取 境外投资企业(机构) 名录。 分析思路: Step 1: 安装splinter 百度 splinter 安装 ,建议安装anaconda(python常用库就基本有了),再安装splinter Step 2: 利用splinter打开chrome,访问链接 from splinter import Browser browser = Browser ( 'chrome' ) #打开谷歌浏览器 browser .visit ( 'http://femhzs.mofcom.gov.cn/fecpmvc/pages/fem/CorpJWList.html' ) #访问链接 打开谷歌浏览器,访问链接.png Step 3: 获取信息 在网页空白处,点击右键,选择“ 检查 ”。然后,在出现的功能框中,用鼠标点击 选择元素 检查.png 点击了选择元素之后

splinter实现浏览器自动登录

a 夏天 提交于 2020-04-04 19:16:58
(1)秒抢火车票,目前状态:未成功,需要后续调试 # -*- coding: utf-8 -*- ''' Created on 2017年7月14日 @author: Administrator ''' from splinter.browser import Browser import time #b=Browser('chrome') url='https://kyfw.12306.cn/otn/leftTicket/init' b=Browser('chrome') b.visit(url) b.find_by_text(u'登录').click() b.fill('loginUserDTO.user_name','*******') b.fill('userDTO.password','*****') time.sleep(5) #填出发地目的地 #用cookie填写相关信息,保持了登陆的状态 b.cookies.add({'leftTicketDTO.from_station_name':u'西安'}) b.cookies.add({'leftTicketDTO.to_station_name':u'北京'}) b.cookies.add({'leftTicketDTO.train_date':'2017-07-22'}) #加载查询 b.reload() b.find

模拟浏览器之从 Selenium 到splinter

微笑、不失礼 提交于 2020-02-13 16:35:16
Splinter是现有浏览器自动化工具(如 Selenium 和 zope.testbrowser) 之上的抽象层 。 它有一个 高级API ,可以轻松编写Web应用程序的自动化测试。 例如,要使用Splinter填写表单字段: browser.fill('username', 'janedoe') 在Selenium中,等效代码为: elem = browser.find_element.by_name('username') elem.send_keys('janedoe') 因为Splinter是一个抽象层,所以它支持多个Web自动化后端。 使用Splinter,您可以使用相同的测试代码进行基于浏览器的测试,使用Selenium作为后端,使用zope.testbrowser作为后端进行“无头”测试(无GUI)。 来源: https://www.cnblogs.com/wdmx/p/10233089.html

Python splinter 环境搭建

一笑奈何 提交于 2020-02-11 10:25:52
今天无意间看到了splinter。 Splinter是一个使用Python开发的开源Web应用测试工具。它可以帮你实现自动浏览站点和与其进行交互。 Splinter对已有的自动化工具(如:Selenium、PhantomJS和zope.testbrowser)进行抽象,形成一个全新的上层应用API,它使为Web应用编写自动化测试脚本变的更容易。 依赖包 编辑 Splinter0.7.2依赖以下包: Selenium(版本>=2.44.0) Django(版本>=1.5.8,<1.7) Flask(版本>=0.10) lxml(版本>=2.3.6) zope.testbrowser(版本>=4.0.4) cssselect 代码示例 使用示例 from splinter import Browser with Browser() as browser: # Visit URL url = "搜索引擎" browser.visit(url) browser.fill('q', 'splinter - python acceptance testing for web applications') # Find and click the 'search' button button = browser.find_by_name('btnG') # Interact with

splinter & chromedriver 模拟操作网页

守給你的承諾、 提交于 2020-01-24 10:11:46
splinter & chromedriver 模拟操作网页 PS: 也是从网上各个帖子中学习的Python,因此代码的格式以及内容有粘贴网上其他大神的代码,如有侵权请告知删除 以12306为例,粘贴的代码为部分代码,理解意思就好 1 模拟登录 登录网址:https://kyfw.12306.cn/otn/login/init 如上图所示,输入用户名的name为loginUserDTO.user_name,同理,输入密码的name为userDTO.password,因此用以下代码进行网页填充 #self是声明的类 self . driver . visit ( "https://kyfw.12306.cn/otn/login/init" ) sleep ( 1 ) self . driver . fill ( 'loginUserDTO.user_name' , "123456" ) self . driver . fill ( 'userDTO.password' , "654321" ) 2 Chromedriver调用 self . driver = Browser ( driver_name = "chrome" , executable_path = "D : \\Program Files ( x86 ) \\ChromeCore\\Chromedriver . exe

can we change the css , html values using splinter , beautiful soup or selenium?

99封情书 提交于 2020-01-07 04:55:47
问题 can i change the value of any html , css thing using splinter or selenium like we can do with inspect element : `<form action="/action_page.php" oninput="x.value=parseInt(a.value)+parseInt(b.value)"> 0 <input type="range" id="a" name="a" value="50"> 100 + <input type="number" id="b" name="b" value="50"> = <output name="x" for="a b"></output> <br><br> <input type="submit"> </form>` can i select <input type="range" id="a" name="a" value="50"> and can change the value="30" by using splinter or

Web page already open (in source format); just need to read that text, using Selenium

♀尐吖头ヾ 提交于 2019-12-24 22:27:31
问题 Let's say I have a tab already open in the browswer. Its URL is: view-source:http://www.google.com/webhp?source=search_app Now that it's already open and displayed, I just want to read the text that's in the client window. (Get a context to the page, or obtain its object (as opposed to creating a new browser object), or whatever. Then just read the page.) Is there any methodology in Selenium, Splinter that allows for that? Thanks for any help. 回答1: If you are asking if you can attach to an