简体   繁体   中英

Selenium get all a tags after comma

I would like to get all the researchers (inside tags) that contributed in an article. Html codes in below.

<div class="projectMain">
    <div class="projectSetting"></div>
    <span class="badge">1</span>
    <span class="Header">...</span>
    <div class="projectAutor"></div>
    <a id="popoverData"> XXX </a>
    ","
    <a id="popoverData"> YYY </a>
    ","
    <a id="popoverData"> ZZZ </a>
</div>

I write this code.

result=[i.text for i in driver.find_elements(By.XPATH,"/html/body/div/div[2]/div[2]/div[2]/div/div[1]/div/div/div//following::a")]

Since an author works with more than one person in more than one article, the code brings the people who work for each article. But this code returns the results as a list like

XXX
YYY
ZZZ

I want to get all a tag by selenium XXX,YYY,ZZZ . How can I include comma in XPath?

Can't you just join the list?

list = ["XXX", "YYY", "ZZZ"]
string = ', '.join(list)
# string = "XXX, YYY, ZZZ"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM