Python Forum
[SOLVED] [BeautifulSoup] Turn select() into comma-separated string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] [BeautifulSoup] Turn select() into comma-separated string?
#1
Hello,

I found no example in the tutorial and other sources.

With a select(), I need to find all the elements that match, and turn the results into a comma-separated string, eg. "Author 1, Author 2, Author 3".

I do find the elements, but fail turning them into to a string:
authors_select = soup.select("a[href*=authors]") #OK
authors = ','.join(authors_select)
authors = ','.join(map(str, soup.select("a[href*=authors]"))) 
authors = ','.join(map(str, soup.select("a[href*=authors]").text)) 
print("Authors=",authors)
Thank you.

---
Edit: Found a way

delim = ','
authors = ''
for str in soup.select("a[href*=authors]"):
	authors += (str.text + delim)				
print("Authors=",authors)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Getting python's default 'printed' byte-string as string ? MvGulik 8 136 Apr-06-2026, 09:16 AM
Last Post: Dustbunny
Thumbs Up Select Python comment (#) [solved] SpongeB0B 7 3,483 Sep-28-2025, 06:39 PM
Last Post: tester_V
Question [SOLVED] Open file, and insert space in string? Winfried 7 2,524 May-28-2025, 07:56 AM
Last Post: Winfried
Question [SOLVED] [Beautiful Soup] Replace tag.string from another file? Winfried 2 1,673 May-01-2025, 03:43 PM
Last Post: Winfried
  gpiozero button turn off LED that is already on duckredbeard 3 1,885 Dec-11-2024, 06:23 PM
Last Post: duckredbeard
  [SOLVED] Sub string not found in string ? jehoshua 4 2,311 Dec-03-2024, 09:17 PM
Last Post: jehoshua
Question [SOLVED] How to replace characters in a string? Winfried 2 1,957 Sep-04-2024, 01:41 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Why are some elements ignored? Winfried 5 2,941 Sep-04-2024, 09:34 AM
Last Post: Winfried
  Exceeding the value - turn on the relay. stsxbel 0 963 May-27-2024, 07:18 PM
Last Post: stsxbel
  [SOLVED] [BeautifulSoup] Why attribute not found? Winfried 0 1,693 Mar-11-2023, 10:00 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020