The problem is that you have 2 Divs with class nm-features-container
for each element. The right one then would be for you to be more specific about which div you want. Looking at HTML, there is a div that has a second class (nm-automaker-list-view
). Filtering by 2, it is possible to pick up only one element.
Example of scraping:
import requests
import bs4
URL = 'https://busca.autoline.com.br/comprar/carros/novos-seminovos-usados/todos-os-estados/todas-as-cidades/todas-as-marcas/todos-os-modelos/todas-as-versoes/todos-os-anos/todas-as-cores/todos-os-precos/'
response = requests.get(URL)
soup = bs4.BeautifulSoup(response.content)
containers = soup.find_all('div', attrs={'class': "nm-features-container nm-automaker-list-view"})
for container in containers:
km = container.find('div', attrs={'class': 'nm-features nm-km '}).get_text().strip()
city = container.find('div', attrs={'class': 'nm-city-tooltip'}).get_text().strip()
print (km, city)
>> 27.000 Frederico Westphalen, RS
>> 50.000 Três Passos, RS
>> 120.000 Três Passos, RS
Important you [Dit] your post and explain in detail the part that is having problem, describing what you tried and where is the current difficulty, preferably with a [mcve]. Studying the post available on this link can make a very positive difference in your use of the site: Stack Overflow Survival Guide in English
– Bacco