如何使用python从HTML过滤字符串列表

问题描述 投票:-1回答:1

人们,我想打印逗号后的字符串列表。

userName = driver.find_elements_by_css_selector('div[class=\'linkedAccountUserName\']')
for i in range(len(userName)):
  print(userName[i].text) 

上面是我的代码

输出:

My Preferences
Linked Accounts
Ram, Tulasi
Worker | BACG
Ar, Raj
Worker | BACG
Pany, Venkat
Worker | BACG
Sarah Isaacmoon, Joyce
Worker | BACG
Kumar, Akshay
Worker | BACG
Sridharan, Akil
Worker | BACG
Sign Out

预期输出:

Tulasi
Raj
Venkat
Joyce
Akshay
Akil
python selenium selenium-webdriver
1个回答
0
投票
txt= userName[i].text x = txt.split(",",1)[1] print("Result after first split ::: ", x) txt1= x.split(" ", 2) print("Result after second split :::", txt1) x = txt1[1] print("Final Result :::", x)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.