爬虫之动态HTML处理(Selenium与PhantomJS )动态页面模拟点击
动态页面模拟点击
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# python的测试模块
import unittest
from selenium import webdriver
from bs4 import BeautifulSoup
class douyuSelenium(unittest.TestCase):
# 初始化方法
def setUp(self):
self.driver = webdriver.PhantomJS()
#具体的测试用例方法,一定要以test开头
def testDouyu(self):
self.driver.get('http://www.douyu.com/directory/all')
while True:
# 指定xml解析
soup = BeautifulSoup(driver.page_source, 'xml')
# 返回当前页面所有房间标题列表 和 观众人数列表
titles = soup.find_all('h3', {'class': 'ellipsis'})
nums = soup.find_all('span', {'class': 'dy-num fr'})
# 使用zip()函数来可以把列表合并,并创建一个元组对的列表[(1,2), (3,4)]
for title, num in zip(nums, titles):
print u"观众人数:" + num.get_text().strip(), u"\t房间标题: " + title.get_text().strip()
# page_source.find()未找到内容则返回-1
if driver.page_source.find('shark-pager-disable-next') != -1:
break
# 模拟下一页点击
self.driver.find_element_by_class_name('shark-pager-next').click()
# 退出时的清理方法
def tearDown(self):
print '加载完成...'
self.driver.quit()
if __name__ == "__main__":
unittest.main()
爬虫之动态HTML处理(Selenium与PhantomJS )动态页面模拟点击的更多相关文章
- 七、Selenium与phantomJS----------动态页面模拟点击、网站模拟登录
每天一个小实例1(动态页面模拟点击,并爬取你想搜索的职位信息) from selenium import webdriver from bs4 import BeautifulSoup # 调用环境变 ...
- Python爬虫开发【第1篇】【动态HTML、Selenium、PhantomJS】
JavaScript JavaScript 是网络上最常用也是支持者最多的客户端脚本语言.它可以收集用户的跟踪数据,不需要重载页面直接提交表单,在页面嵌入多媒体文件,甚至运行网页游戏. 我们可以在网页 ...
- 爬虫之动态HTML处理(Selenium与PhantomJS )网站模拟登录
#coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport tim ...
- selenium + firefox/chrome/phantomjs登陆之模拟点击
登陆之模拟点击 工具:python/java + selenium + firefox/chrome/phantomjs (1)windows开发环境搭建 默认已经安装好了firefox 安装pip ...
- python爬虫积累(一)--------selenium+python+PhantomJS的使用(转)
阅读目录 一.Selenium介绍 二.爬虫为什么要用selenium? 三.PhantomJS介绍 四.PhantomJS安装 五.操作实战 六.在此推荐虫师博客的学习资料 selenium + p ...
- python爬虫积累(一)--------selenium+python+PhantomJS的使用
最近按公司要求,爬取相关网站时,发现没有找到js包的地址,我就采用selenium来爬取信息,相关实战链接:python爬虫实战(一)--------中国作物种质信息网 一.Selenium介绍 Se ...
- python爬虫入门(五)Selenium模拟用户操作
爬虫(Spider),反爬虫(Anti-Spider),反反爬虫(Anti-Anti-Spider) 之间恢宏壮阔的斗争... 小莫想要某站上所有的电影,写了标准的爬虫(基于HttpClient库), ...
- [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
前面几篇文章介绍了Selenium.PhantomJS的基础知识及安装过程,这篇文章是一篇应用.通过Selenium调用Phantomjs获取CSDN下载资源的信息,最重要的是动态获取资源的评论,它是 ...
- [Python爬虫] 之一 : Selenium+Phantomjs动态获取网站数据信息
本人刚才开始学习爬虫,从网上查询资料,写了一个利用Selenium+Phantomjs动态获取网站数据信息的例子,当然首先要安装Selenium+Phantomjs,具体的看 http://www.c ...
随机推荐
- make_ext4fs 失败
root@fengyun-server:/home/fmake_ext4fsengyun/android/reverse_engineer/rom制作# ./make_ext4fs -l 700M - ...
- Chrome cookies folder
w本地存储数据2种形式. http://superuser.com/questions/292952/chrome-cookies-folder-in-windows-7 chrome://setti ...
- 算法大神之路——排序
从今天开始,给自己立下一个目标,每天晚上写一篇算法与数据结构的博客,用来给自己以后的算法工程师的目标铺路! 今天晚上就以算法里面的排序,作为自己的第一章节吧. 排序,就是讲一组数据,按照特定的规则去调 ...
- 前端开发 - HTML - 总结
html head标签 title 显示网站的标题 meta 提供有关页面的原信息 link 链接css资源文件.网站图标 style 定义内部样式表 script 链接脚本js文件 body标签 块 ...
- Qt JSON解析生成笔记(把JSON转成一个类对象)
对于这样一段json { "name": "布衣食", "gender": "Male", "age" ...
- linux下的KSM内存共享机制分析
2017-04-26 KSM是内核中的一种内存共享机制,在2.6.36版本的内核中开始引入,简单来说就是其会 合并某些相同的页面以减少页面冗余.在内核中有一个KSM守护进程 ksmd,它定期扫描用户向 ...
- Linux上安装rz和sz命令
简介 lrzsz 官网入口:http://freecode.com/projects/lrzsz/ lrzsz是一个unix通信套件提供的X,Y,和ZModem文件传输协议 windows 需要向ce ...
- swagger接口变动监控
版本与版本之间迭代,总会发生接口的变化,而这些变化开发不会都告诉测试,测试需要把全部接口检查一遍,这样就降低了测试效率. 为了解决这个问题,结合公司实际项目进行了以下设计: 1.对比测试环境swagg ...
- PAT 1115 Counting Nodes in a BST[构建BST]
1115 Counting Nodes in a BST(30 分) A Binary Search Tree (BST) is recursively defined as a binary tre ...
- git pull和git merge区别&&Git冲突:commit your changes or stash them before you can merge. 解决办法
http://blog.csdn.net/sidely/article/details/40143441 原文: http://www.tech126.com/git-fetch-pull/ Git中 ...