# 利用selenium爬取斗鱼直播的标题,类型,用户,和图片链接(相对request较慢)
import json
import time
from selenium import webdriver
class Douyu(object):
def __init__(self):
self.url = 'https://www.douyu.com/directory/all'
self.driver = webdriver.Chrome()
self.file = open('douyu.json','w')
def parse_data(self):
# 获取页面元素列表
node_list= self.driver.find_elements_by_xpath('//*[@id="live-list-contentbox"]/li/a')
detail_list =[]
for node in node_list:
temp={}
temp['title'] = node.find_element_by_xpath('./div/div/h3').text
temp['owner']=node.find_element_by_xpath('./div/p/span[1]').text
temp['type']=node.find_element_by_xpath('./div/div/span').text
temp[&#