Getting All Items From A List - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Getting All Items From A List (/thread-35034.html) |
Getting All Items From A List - knight2000 - Sep-24-2021 Hey guys, In practicing some webscrapping with BeautifulSoup and Selenium. Using the find_all to extract a class, I get the following list: Here's a snippet of the code that get's me this:mt2_mb2 = soup.find('div', {'class': 'mt2 mb2'}) span_2 = mt2_mb2.find('span')['class'] print(span_2)What I want to do, is get all of those items together. So in other words, I want to get the output to look like this: Could someone kindly enlighten me how to do this?Thanks a lot. RE: Getting All Items From A List - Yoriz - Sep-24-2021 Do you want them as a single string with a space between each string item of the list? items = ['w_A', 'w_C', 'w_B', 'mr1', 'mt1', 'ph1'] joined_items = ' '.join(items) print(joined_items)
RE: Getting All Items From A List - knight2000 - Sep-25-2021 Hi Yoriz, Yes please, as a single string with a space between each string item. RE: Getting All Items From A List - Yoriz - Sep-25-2021 You can use string's join method as I have shown in the example above.
RE: Getting All Items From A List - knight2000 - Sep-25-2021 (Sep-25-2021, 12:40 AM)Yoriz Wrote: You can use string's Sorry Yoriz- just woke up and must be blind as a bat! I didn't see your code and thought you pasted my code in there to query. Thanks so much. Never heard of the join method- will definitely take a note of that for future. Have a great one. |