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
  gpiozero button turn off LED that is already on duckredbeard 3 840 Dec-11-2024, 06:23 PM
Last Post: duckredbeard
  [SOLVED] Sub string not found in string ? jehoshua 4 1,416 Dec-03-2024, 09:17 PM
Last Post: jehoshua
Question [SOLVED] How to replace characters in a string? Winfried 2 1,045 Sep-04-2024, 01:41 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Why are some elements ignored? Winfried 5 1,698 Sep-04-2024, 09:34 AM
Last Post: Winfried
  Exceeding the value - turn on the relay. stsxbel 0 582 May-27-2024, 07:18 PM
Last Post: stsxbel
  [SOLVED] [BeautifulSoup] Why attribute not found? Winfried 0 1,268 Mar-11-2023, 10:00 PM
Last Post: Winfried
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 1,917 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 2,711 Sep-03-2022, 11:21 PM
Last Post: Winfried
  [SOLVED] [Beautifulsoup] Find if element exists, and edit/append? Winfried 2 7,033 Sep-03-2022, 10:14 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] How to get this text? Winfried 6 3,160 Aug-17-2022, 03:58 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