Selenium实战案例
from selenium.webdriver.chrome.service import Service
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from lxml import etree
def spider_huya():
service = Service('./chromedriver.exe')
driver = Chrome(service=service)
driver.implicitly_wait(5)
driver.get('https://www.huya.com/g/lol')
count = 1
while True:
e = etree.HTML(driver.page_source)
names = e.xpath('//i[@class="nick"]/@title')
person_nums = e.xpath('//i[@class="js-num"]/text()')
if driver.page_source.find('laypage_next') == -1:
break
next_btn = driver.find_element(By.XPATH,'//a[@class="laypage_next"]')
next_btn.click()
driver.quit()
if __name__ == '__main__':
spider_huya()