I'm opening two links from links.txt and outputting to names.txt.
I'm trying to get rid of the word: "FEATURING" and add: ", " between the elements.
Current output:
FEATURING
Arietta AdamsIsiah MaxwellFEATURING
Vanessa VegaRichard Mann
Desired output:
Arietta Adams, Isiah Maxwell
Vanessa Vega, Richard Mann
My code:
one = open("links.txt", "r")
for two in one.readlines():
driver.get(two)
sleep(3)
for element in driver.find_elements_by_class_name('sceneColActors'):
with open("names.txt", "a") as testtxt:
testtxt.write(element.text)
Html:
<div > == $0
<b>Featuring </b>
<a href="/en/Arietta-Adams/58224" title="Arietta Adams">Arietta Adams</a>
<span >, </span>
<a href="/en/Isiah-Maxwell/34204" title="Isiah Maxwell">Isiah Maxwell</a>
Here's a screenshot of the html just in case.
CodePudding user response:
I suppose you should try to get a
tags separately. Try
driver.find_elements_by_css_selector('.sceneColActors a')
instead of
driver.find_elements_by_class_name('sceneColActors')
And now you can get all needed words separately and you just add delimiter ,
between them.