from selenium import webdriver
import time
from bs4 import BeautifulSoup class douyuSelenium():
#初始化,启动斗鱼浏览器
def setUp(self):
self.driver = webdriver.PhantomJS() #获取斗鱼房间信息
def testDouyu(self):#'https://www.douyu.com/directory/all'
self.driver.get('https://www.douyu.com/directory/all')
while True: time.sleep(2)
#指定解析器,生成一个soup对象
soup = BeautifulSoup(self.driver.page_source,'lxml') #获取当前页面所有的房间标题,观众人数
titles = soup.find_all('h3',{'class':'ellipsis'})
nums = soup.find_all('span',{'class':'dy-num fr'})
for title,num in zip(titles,nums):
info = "房间标题:" + title.get_text().strip() + '\t' + "人气:" + num.get_text().strip()
print(info) #下一页
#查找下一页 在最后一页会有shark-pager-disable-next元素 表示没有下一页
if self.driver.page_source.find('shark-pager-disable-next') != -1:
break #点击 页面到下一页
next_page = self.driver.find_element_by_class_name('shark-pager-next')
next_page.click() def shutdown(self):
print('加载完成...')
#加载完成 退出浏览器
self.driver.quit() if __name__ == '__main__':
douyu = douyuSelenium()
douyu.setUp()
douyu.testDouyu()
douyu.shutdown()

selenium,webdriver爬取斗鱼主播信息 实操的更多相关文章

  1. 『Scrapy』爬取斗鱼主播头像

    分析目标 爬取的是斗鱼主播头像,示范使用的URL似乎是个移动接口(下文有提到),理由是网页主页属于动态页面,爬取难度陡升,当然爬取斗鱼主播头像这么恶趣味的事也不是我的兴趣...... 目标URL如下, ...

  2. 爬虫之selenium爬取斗鱼主播图片

    这是我GitHub上简单的selenium介绍与简单使用:https://github.com/bwyt/spider/tree/master/selenium%E5%9F%BA%E7%A1%80 & ...

  3. 【爬虫小程序:爬取斗鱼所有房间信息】Xpath

    # 本程序亲测有效,用于理解爬虫相关的基础知识,不足之处希望大家批评指正from selenium import webdriver import time class Douyu: "&q ...

  4. [python爬虫] Selenium定向爬取PubMed生物医学摘要信息

    本文主要是自己的在线代码笔记.在生物医学本体Ontology构建过程中,我使用Selenium定向爬取生物医学PubMed数据库的内容.        PubMed是一个免费的搜寻引擎,提供生物医学方 ...

  5. 【爬虫小程序:爬取斗鱼所有房间信息】Xpath(多进程版)

    # 本程序亲测有效,用于理解爬虫相关的基础知识,不足之处希望大家批评指正 import requests from lxml import etree from multiprocessing imp ...

  6. 【爬虫小程序:爬取斗鱼所有房间信息】Xpath(协程池版)

    # 本程序亲测有效,用于理解爬虫相关的基础知识,不足之处希望大家批评指正 from gevent import monkey monkey.patch_all() from gevent.pool i ...

  7. 【爬虫小程序:爬取斗鱼所有房间信息】Xpath(线程池版)

    # 本程序亲测有效,用于理解爬虫相关的基础知识,不足之处希望大家批评指正 from queue import Queue import requests from lxml import etree ...

  8. 【爬虫小程序:爬取斗鱼所有房间信息】Xpath(多线程版)

    # 本程序亲测有效,用于理解爬虫相关的基础知识,不足之处希望大家批评指正 from queue import Queue import requests from lxml import etree ...

  9. python实战之原生爬虫(爬取熊猫主播排行榜)

    """ this is a module,多行注释 """ import re from urllib import request # B ...

随机推荐

  1. Little Sub and Mr.Potato's Math Problem (构造法)

    题目传送门Little Sub and Mr.Potato's Math Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB Littl ...

  2. 攻防世界--game

    题目链接:https://adworld.xctf.org.cn/task/answer?type=reverse&number=4&grade=0&id=5074 1.准备 ...

  3. 5.把报表集成到Web应用程序中-生成网页和导出两种方式

    转自:https://wenku.baidu.com/view/104156f9770bf78a65295462.html 第四部分,把报表集成到Web应用程序中 用MyEclipse新建一个Web ...

  4. 2018-2-13-win10-uwp-分治法

    title author date CreateTime categories win10 uwp 分治法 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:2 ...

  5. 关于.net中使用reportview所需注意

    参考文章链接:http://www.cnblogs.com/watercold/p/5258608.html 这段时间在做一个winform的小项目时,发现使用.net中的ReportViewer插件 ...

  6. Sass--混合宏 VS 继承 VS 占位符

    什么时候用混合宏,什么时候用继承,什么时候使用占位符?”其实他们各有各的优点与缺点,先来看看他们使用效果: a) Sass 中的混合宏使用 总结:编译出来的 CSS 清晰告诉了大家,他不会自动合并相同 ...

  7. 阿里腾讯校招Java面试题总结及答案

    阿里校招java面试题汇总 1.HashMap和HashTable的区别,及其实现原理. Hashtable继承自Dictionary类,而HashMap是Java1.2引进的,继承自Abstract ...

  8. https://geewu.gitbooks.io/rabbitmq-quick/content/RabbitMQ%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C.html

    https://geewu.gitbooks.io/rabbitmq-quick/content/RabbitMQ%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C.html

  9. canvas 操作像素 窗帘效果

    代码实例: <!DOCTYPE html> <html> <head> <style> canvas{ background:#eee; } </ ...

  10. bzoj4489 [Jsoi2015]地铁线路 最短路

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4489 题解 感觉又被骗了.看这道题的 AC 人数不多,以为是一道很好的题目.结果发现是一个非常 ...