selenium2使用记录
安装 pip install selenium
web
phantomjs下载 :http://phantomjs.org/download.html
浏览器驱动下载:http://www.seleniumhq.com/download
chrome: http://chromedriver.storage.googleapis.com/index.html?path=2.22/
#!/usr/bin/env python # encoding: utf-8 from selenium import webdriver driver = webdriver.Chrome() url = 'http://www.toutiao.com/news_fashion/' driver.get(url) print driver.title
爬取今日头条实例,使用刷新方法,来改变文章内容,暂时还不会控制鼠标滑动来实现
#!/usr/bin/env python # encoding: utf-8 import time from selenium import webdriver import itertools driver = webdriver.Chrome() url = 'http://www.toutiao.com/news_fashion/' driver.get(url) print driver.get(url) for x in range(2): driver.refresh() titles = driver.find_elements_by_class_name("title-box") contents = driver.find_elements_by_class_name("abstract") imgs = driver.find_element_by_css_selector(".feedimg") for title, content, img in zip(titles, contents, itertools.repeat(imgs)): data = { 'title': title.text, 'content': content.text, 'img': img.get_attribute('src') } print data time.sleep(10) driver.close()
自动登陆的例子:
# coding:utf-8 import requests from bs4 import BeautifulSoup from selenium import webdriver import time #有验证码 driver = webdriver.Chrome() url = 'http://mp.sohu.com/' driver.get(url) driver.find_element_by_id("userid").clear() driver.find_element_by_id('userid').send_keys("username") driver.find_element_by_id("pwd").clear() driver.find_element_by_id("pwd").send_keys('password') driver.find_element_by_id("loginbutton").click() time.sleep(2) driver.close()
scrapy+selenium+phantomjs
class judge(Spider): name = "judge" start_urls = ["http://wenshu.court.gov.cn/List/List?sorttype=1&conditions=searchWord+2+AJLX++%E6%A1%88%E4%BB%B6%E7%B1%BB%E5%9E%8B:%E6%B0%91%E4%BA%8B%E6%A1%88%E4%BB%B6"] def init_driver(self): driver = webdriver.Chrome() return driver def parse(self,response): driver = self.init_driver() driver.get(self.start_urls[0]) sel = Selector(text=driver.page_source) self.logger.info(u'---------------Parsing----------------') print sel.xpath("//div[@class='dataItem'][1]/table/tbody/tr[1]/td/div[@class='wstitle']/a/text()").extract() self.logger.info(u'---------------success----------------')
selenium2使用记录的更多相关文章
- 在MAC下使用Robotframework+Selenium2【第二枪】如何处理Table点击指定记录
1.通过关键字Get Matching Xpath Count获取table中的记录 2.遍历Table所有记录 3.判断记录是否符合条件,做点击操作
- selenium2(WebDriver)环境搭建
1.安装jdk并配置环境变量: jdk安装jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html环境变量 ...
- Selenium2学习-004-WebUI自动化实战实例-002-百度登录
此文主要通过 百度登录 功能,进行 Selenium2 的实战实例讲解.文中所附源代码于 2015-01-17 23:33 亲测通过,敬请亲们阅览.同时,您也可参考此文进行其他网站(例如 京东.易迅. ...
- selenium2 安装、简单使用及浏览器启动问题解决汇总
一.selenium2 安装 1.安装jdk并配置环境变量 jdk需要1.6版本及以上的,这个从网上下载就可以,环境变量的配置前边的随笔整理过就不多说了. 2.安装Firefox,Selenium I ...
- selenium2.0处理case实例(二)
本文通过具体代码处理过程, 来展示selenium中一些比较不常用的类的用法 1.javascriptExcutor,通过将driver强转成JavascriptExecutor类型, 调用execu ...
- selenium1,selenium2,watir的比较
接触web方面的自动化测试,会接触几个常用的工具,selenium1,selenium2,watir 有的时候总是混淆,那么他们的优缺点啥的呢,在让你给项目选自动化框架,会选择哪个??? 1,语言的支 ...
- 转:Selenium2.0 click()不生效的解决办法
除了http://573301735.com/?p=5126讲的,昨天又发现一个让我1个小时生不如死的问题,就是使用两个不同的配置文件来初始化driver,findelement方法获取到的坐标居然不 ...
- 基于Selenium2与Python自动化测试环境搭建
简介: selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: * 免费,也不用再为破解QTP而大伤脑筋 * 小巧,对于 ...
- 自动化测试之 seleniumIDE,Selenium1,selenium2和testNG入门
由于前期三个月公司的项目一直在改需求阶段,一直是手动测试,现在项目雏形以及基本页面功能都确定下来,为了不让自己陷入天天测同一功能的无限循环中,故开始自动化测试的学习之路,也为自己以后的发展铺铺路. 一 ...
随机推荐
- 一步一步实现基于Task的Promise库(四)无参数的WorkItem
接着上一篇我直接给出代码,现在支持了new Task(), then(), all(), any() 这些不传参的调用方式. (function(){ var isFunction = functio ...
- MVC 控制器激活
MVC 控制器激活 ASP.NET MVC 控制器激活(三) 前言 在上个篇幅中说到从控制器工厂的GetControllerInstance()方法来执行控制器的注入,本篇要讲是在GetControl ...
- Vijos:P1001谁拿了最多奖学金
描述 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以 ...
- HBase的索引
LSM树由来.设计思想以及应用到HBase的索引 讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎 是哈希表的持久化实现,支持增.删.改以及随机读取操作,但 ...
- [原]Escape From the iOS Sanbox on Jailbreak Device
just my thinking, 3 ways to escape from sandbox on jailbreak device, to do file copying or execute s ...
- iOS国际化和genstrings所有子目录本地化字符串
最近在忙着一个国外项目,天天加班,没时间更新博客.就简单讲讲国际化的知识. 首先,我们使用字符串,必须用NSLocalizedString(key,comment),这样我们在不同的Localizab ...
- 系统架构、网络通信、IM、视频会议技术
专注于系统架构.网络通信.IM.视频会议技术. 主要作品: ESFramework 强悍的通信框架.P2P框架.群集平台. OMCS 简单易用的 网络语音视频 框架. MFile 语音视频录制组件. ...
- C#执行cmd命令
public class Console : IRun { public Console(){ ; } public string Result { get; set; } public string ...
- jquery选择器之基本过滤选择器
<style type="text/css"> /*高亮显示*/ .highlight{ background-color: gray } </style> ...
- .Net项目框架
摘要:本文描述了在用VS.NET进行B/S开发时采用的框架结构,一般建立类库项目和Web项目,在Web基本aspx页面类中调用类库中方法,同时在aspx页面类中不需要写任何对数据库操作的SQL代码,便 ...