beautifulsoup returns data without spaces

Viewed 35

I´m trying to web scrap this domain: "carros.mercadolibre.com.co" using beatifulSoup and it works but returns a list without spaces.

How can I make to return a list with commas, that can be converted into a data frame?

My guess is that I didn´t choose the class well.

This is the code:

import requests
from bs4 import BeautifulSoup
r = requests.get('https://carros.mercadolibre.com.co/')
soup = BeautifulSoup(r.content, 'html.parser')
titles =soup.find_all('li',attrs={"class":"ui-search-layout__item"})
titles = [i.text for i in titles]
print(titles)
1 Answers

.text eliminates all tags (namely, the <div> and <p> tags that separate the words in your example). Use .strings instead:

titles = [" ".join(i.strings) for i in titles]
Related