安装 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使用记录的更多相关文章

  1. 在MAC下使用Robotframework+Selenium2【第二枪】如何处理Table点击指定记录

    1.通过关键字Get Matching Xpath Count获取table中的记录 2.遍历Table所有记录 3.判断记录是否符合条件,做点击操作

  2. selenium2(WebDriver)环境搭建

    1.安装jdk并配置环境变量: jdk安装jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html环境变量 ...

  3. Selenium2学习-004-WebUI自动化实战实例-002-百度登录

    此文主要通过 百度登录 功能,进行 Selenium2 的实战实例讲解.文中所附源代码于 2015-01-17 23:33 亲测通过,敬请亲们阅览.同时,您也可参考此文进行其他网站(例如 京东.易迅. ...

  4. selenium2 安装、简单使用及浏览器启动问题解决汇总

    一.selenium2 安装 1.安装jdk并配置环境变量 jdk需要1.6版本及以上的,这个从网上下载就可以,环境变量的配置前边的随笔整理过就不多说了. 2.安装Firefox,Selenium I ...

  5. selenium2.0处理case实例(二)

    本文通过具体代码处理过程, 来展示selenium中一些比较不常用的类的用法 1.javascriptExcutor,通过将driver强转成JavascriptExecutor类型, 调用execu ...

  6. selenium1,selenium2,watir的比较

    接触web方面的自动化测试,会接触几个常用的工具,selenium1,selenium2,watir 有的时候总是混淆,那么他们的优缺点啥的呢,在让你给项目选自动化框架,会选择哪个??? 1,语言的支 ...

  7. 转:Selenium2.0 click()不生效的解决办法

    除了http://573301735.com/?p=5126讲的,昨天又发现一个让我1个小时生不如死的问题,就是使用两个不同的配置文件来初始化driver,findelement方法获取到的坐标居然不 ...

  8. 基于Selenium2与Python自动化测试环境搭建

    简介: selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: *  免费,也不用再为破解QTP而大伤脑筋 *  小巧,对于 ...

  9. 自动化测试之 seleniumIDE,Selenium1,selenium2和testNG入门

    由于前期三个月公司的项目一直在改需求阶段,一直是手动测试,现在项目雏形以及基本页面功能都确定下来,为了不让自己陷入天天测同一功能的无限循环中,故开始自动化测试的学习之路,也为自己以后的发展铺铺路. 一 ...

随机推荐

  1. 学习Sass之安装Sass

    学习Sass之安装Sass 为什么使用Sass 作为前端(html.javascript.css)的三大马车之一的css,一直以静态语言存在,HTML5火遍大江南北了.javascript由于NODE ...

  2. WCF的简单

    WCF的简单 WCF的学习之旅 一.WCF的简单介绍  Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows ...

  3. Ubuntu下安装Pyqt4

    确保系统中安装有python之后,在终端输入: sudo apt-get install libxext6 libxext-dev libqt4-dev libqt4-gui libqt4-sql q ...

  4. Ajax运用总结B

    Jquery重新学习之八[Ajax运用总结B]   上一篇简单介绍普通javascript以及Jquery的AJAX方法,其中Jquery.ajax()是功能比较强悍的底层方法,可以更多地关注实现过程 ...

  5. DNN简介以及安装

    开源框架DNN简介以及安装 donetnuke 是一款免费的开源cms框架,目前也有收费版,不过免费版也可以适应大家大部分的需求.我前些阵子是老板让我在20天内,做好一个官网并且发布,并且指定使用dn ...

  6. git命令与github使用

    GitHub 是一个类似 SourceForge 的免费项目管理及分享的服务平台,要想使用 github,用户可以免费注册成为 github 注册用户,之后使用git命令进行操作使用.github 的 ...

  7. Windows Serer 2003 配置手册 – 创建Active Dictionary域

    域与工作组的关系 实际上我们可以把域和工作组联系起来理解,在工作组上你一切的设置在本机上进行包括各种策略,用户登录也是登录在本机的,密码是放在本机的数据库来验证的.而如果你的计算机加入域的话,各种策略 ...

  8. 初试KONCKOUT+WEBAPI简单实现增删改查

    初试KONCKOUT+WEBAPI简单实现增删改查 前言 konckout.js本人也是刚刚接触,也是初学,本文的目的是使用ko和asp.net mvc4 webapi来实现一个简单增删改查操作.Kn ...

  9. 应用程序入口 WSGIHandler

    Django 源码小剖: 应用程序入口 WSGIHandler WSGI 有三个部分, 分别为服务器(server), 应用程序(application) 和中间件(middleware). 已经知道 ...

  10. StreamWriter(ms, new UTF8Encoding(false))可以达到不输出BOM的需求。

    winform 通过webservice向服务器提交图片需要注意的地方 最近一个winform项目中需要通过拍照或者上传本地文件或者截图的方式把产品图片上传到服务器,最后选择了服务器部署webserv ...