以百度首页为例
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
elements = driver.find_elements(By.CLASS_NAME, 'title-content-title')
array=[]
for element in elements:
array.append(element.text)
print (array)
运行结果
['这张冬奥大合影弥足珍贵', '中国队晋级短道女子3000米接力决赛', '任子威被判犯规无缘决赛', '任子威回应犯规:出现了低级失误', '人类应该和衷共济和合共生', '刘少林破速滑1500米奥运纪录']