使用selenium爬取斗鱼直播数据

本文介绍如何运用selenium库抓取斗鱼直播首页数据。通过模拟浏览器跳转,定位到目标页面,然后使用xpath表达式提取所需信息,对数据进行分析并保存。
摘要由CSDN通过智能技术生成
  1. 分析斗鱼直播首页https://www.douyu.com/directory/all
  2. 使用selenium来实现跳转页面,定位到跳转页面位置。
  3. 拿到页面后通过xpath提取想要的数据进行分析。
  4. 保存数据

 

# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from lxml import etree
import csv


#把浏览器设为无头模式
chrome_option = Options()
chrome_option.add_argument('-headless')
browser =  webdriver.Chrome(chrome_options=chrome_option)


def get_next_page(n):
    '''获取下一页页面'''
    # 1.找到下一页的标签,点击进行跳转
    browser.find_element_by_class_name('jumptxt').send_keys(n)
    brows
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值