Python 3.x Python/Selenium-在字符之前打印元素的文本

Python 3.x Python/Selenium-在字符之前打印元素的文本,python-3.x,selenium,Python 3.x,Selenium,我正在尝试打印bing搜索结果列表中的名称。我可以抓住整个标题,但只需要在“-”之前输入名称 链接: 我希望输出为: 汤姆·鲍威尔, 马蒂·约翰逊, 马特·加德纳, 等等抓住前面的所有东西-并剥去最后的空间 titles=WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "b_algo"))) name = [div.find_element_by_tag

我正在尝试打印bing搜索结果列表中的名称。我可以抓住整个标题,但只需要在“-”之前输入名称

链接:

我希望输出为: 汤姆·鲍威尔, 马蒂·约翰逊, 马特·加德纳,
等等

抓住前面的所有东西-并剥去最后的空间

titles=WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "b_algo")))
name = [div.find_element_by_tag_name('h2 > a').get_attribute('innerHTML').split('-')[0].strip() for div in titles]
输出

['Lauren Kearl',
 'Tennison Hunter',
 'Doug Blackhurst',
 'Doug Daniels',
 'Connor Hoiland',
 'Drew Dunham',
 'Peter Skaggs',
 'Lindsey Huish',
 'Rachel Hernandez',
 'Joseph Vore']
进口

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

我正在尝试获取结果页面上的所有名称,这样就会抛出一个错误什么类型的错误。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC