I have a scraper that takes a list of elements, then I go through them and add them to an array, see:
try:
get_tags=driver.find_elements(By.XPATH,'//p[@]/a')
lista_tags = []
for tag in get_tags:
lista_tags.append(tag.text)
tags = lista_tags
except:
tags=''
The problem is that the result I get is like this: ['tag1' , 'tag2']
But I need the result like this: tag1, tag2
How can I have the output only comma separated ?
CodePudding user response:
The most pythonic way is use join
function to join list
','.join(['tag1' , 'tag2'])
CodePudding user response:
The ['tag1' , 'tag2']
means you are outputting the list instead of every element in the list separated by a comma as you seem to be looking for.
Essentially what you are doing for output is:
print(lista_tags)
when instead you want something more akin to:
for ent in lista_tags:
print(str(ent) ','),