- 分析斗鱼直播首页https://www.douyu.com/directory/all
- 使用selenium来实现跳转页面,定位到跳转页面位置。
- 拿到页面后通过xpath提取想要的数据进行分析。
- 保存数据
# -*- 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