selenium自动化爬取虎牙直播数据
from selenium import webdriver
import time
driver=webdriver.Chrome()
url='https://www.huya.com/g/wzry'
driver.get(url)
n=1
while True:
print('第---------------'+str(n)+'------------------页')
time.sleep(10)
n+=1
nicks=driver.find_elements_by_xpath('//i[@class="nick"]')
scores=driver.find_elements_by_xpath('//i[@class="js-num"]')
#zip返回的是一个zip对象,是一个元组对象
for nick,score in zip(nicks,scores):
print(nick.text,':',score.text)
#判断是否为真
if driver.page_source.find("laypage_curr")!=-1:
driver.find_element_by_xpath('//a[@class="laypage_next"]').click()
else:
break
driver.quit()