python selenium加bs4批量爬取斗鱼直播信息
2018-03-23 20:16
507 查看
from selenium import webdriver from bs4 import BeautifulSoup import time # 返回Phantomjs对象 driver = webdriver.PhantomJS() # 使用get方法请求 driver.get('https://www.douyu.com/directory/all') f=open("douyu.txt","w",encoding= 'utf-8') i=0 while True: html = driver.page_source # 解析HTML网页源代码 soup = BeautifulSoup(html, 'lxml') room_names = soup.find_all('h3', class_="ellipsis") room_numbers = soup.find_all('span', class_="dy-num fr") i+=1 for room_name, room_number in zip(room_names, room_numbers): name = room_name.get_text().replace("\n","").strip() number = room_number.get_text().replace("\n","").strip() f.write("房间名:" + name +" 房间人数:" + number) f.write("\n") print("已完成第"+str(i)+"页数据爬取") time.sleep(5) # 如果不能翻页,退出循环 if html.find('shark-pager-next shark-pager-disable shark-pager-disable-next') != -1: break driver.find_element_by_class_name('shark-pager-next').click() f.close() driver.close()
相关文章推荐
- Python使用Selenium模块模拟浏览器抓取斗鱼直播间信息示例
- python爬虫之 selenium + phantomjs 爬斗鱼所有直播间
- Python 使用Selenium获取斗鱼直播主播数据(二十二02)
- python使用unittest模块selenium访问斗鱼获取直播信息
- Python爬虫之selenium爬虫,模拟浏览器爬取天猫信息
- Python利用selenium模拟浏览器抓取异步加载等难爬页面信息
- [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
- Python+爬虫技术获取斗鱼直播图片(整理)
- [Python爬虫] Selenium+Phantomjs动态获取CSDN下载资源信息和评论
- Python+Selenium练习篇之30-获取当前页面全部图片信息
- 【Python】模拟登陆并抓取拉勾网信息(selenium+phantomjs)
- Python+Selenium 自动化实现实例-获取页面元素信息
- 用python+selenium从百度获取本地明日的天气信息并根据温度情况邮件提醒
- 使用python利器selenium工具模拟浏览器运行并爬取淘宝商品信息
- Python使用Selenium模块实现模拟浏览器抓取淘宝商品美食信息功能示例
- [Python爬虫] 之二十六:Selenium +phantomjs 利用 pyquery抓取智能电视网站图片信息
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
- Python+Scrapy+Selenium简单爬取淘宝天猫商品信息及评论
- 用python+selenium从百度获取本地明日的天气信息并根据温度情况设置提醒
- [python爬虫] Selenium爬取新浪微博内容及用户信息