Reputation: 5
how do I remove the div brackets? I just want the names of the car models left: "E-Pace", "F-Pace SVR"...
Highly appreciate your input. I am new to coding so would be nice to get your solution.
Thank you
Code:
import requests
import time
#Inputs/URLs to scrape:
URL_model = ('https://carbuzz.com/cars/jaguar')
(response := requests.get(URL_model)).raise_for_status()
soup = BeautifulSoup(response.text, 'lxml')
overview = soup.find()
for car_model in soup.find_all(class_='sub-model-with-score-preview__name'):
car_model
print(car_model)
Output:
E-Pace </div>
<div class="sub-model-with-score-preview__name">
F-Pace SVR </div>
<div class="sub-model-with-score-preview__name">
F-Pace </div>
<div class="sub-model-with-score-preview__name">
I-Pace </div>
<div class="sub-model-with-score-preview__name">
F-Type Coupe </div>
Upvotes: 0
Views: 36
Reputation: 25048
Simply use get_text()
to extract the texts from your tag and use strip parameter to get rid of leasing/ trailing whitespaces or linebreaks:
print(car_model.get_text(strip=True)
Upvotes: 1