安装 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----------------')

  

 

  

 

最新文章

  1. ABP配套代码生成器(ABP Code Generator)帮助文档,实现快速开发
  2. c# Using Settings under visual studio 2012
  3. 【管理心得之九】奉劝那些把组织“玩弄于鼓掌之间”的OL们。(别让组织看见此篇)
  4. HTTP协议之chunk编码(分块传输编码
  5. 2、C#基础整理(运算符、数据类型与转换、var关键字)
  6. JavaScript高级---组合模式设计
  7. python中去掉空行的问题
  8. 基于VMware的eCos环境编译redboot(脚本配置redboot)
  9. HDU2066一个人的旅行/最短路问题
  10. Oracle索引批量重置笔记
  11. 如何获取系统Home(Launcher)应用判断用户是否处于home界面
  12. Java基础:JVM垃圾回收算法
  13. 题解 P3246 【[HNOI2016]序列】
  14. Jenkins+PowerShell持续集成环境搭建(八)邮件通知
  15. LVM管理之减少LV的大小
  16. 用自定义的RoundImageView来实现圆形图片(可加边框)
  17. jQuery.extend 函数
  18. task16 表格增减笔记
  19. 在CMD 中,如何切换python2.x 版本 和 python3.x版本?
  20. iPhone X 的原深感模组

热门文章

  1. ModelBinder——ASP.NET MVC Model绑定的核心
  2. ubuntu下无法打开windows下ntfs文件系统的解决方法
  3. nutch solr 配置
  4. NuGet安装及简单使用
  5. P2P中的NAT穿越方案简介
  6. Vnix项目正式启动
  7. Django 源码小剖: 初探 WSGI
  8. EasyUI 1.3.6 DateBox添加清空按钮
  9. Spring3.2 + Hibernate4.2
  10. centos安装svn