Я удалил некоторые списки веб-сайта и сумел заставить работать большинство функций, кроме удаления описания.
вот URL одного объявления: https://eg.hatla2ee.com/en/car/honda/civic/3289785
Вот мой код:
for link in df['New Carlist Unit 1_link']:
url = requests.get(link)
soup = BeautifulSoup(url.text, 'html.parser')
### Get title
title =[]
try:
title.append(soup.find('h1').text.strip())
except Exception as e:
None
## Get price
price = []
try:
price.append(soup.find('span',class_="usedUnitCarPrice").text.strip())
except Exception as e:
None
##Get Description box
label =[]
text =[]
try:
for span in soup.find_all('span',class_="DescDataSubTit"):
label.append(span.text.strip())
text.append(span.find_next_sibling().text.strip())
except Exception as e:
None
print('*'*100)
print(title)
print(price)
print(label)
print(text)
time.sleep(1)
Я не могу собрать все теги span по некоторым причинам.
Вот вывод, который я хочу:
{'Make': 'Honda'}
{'Model': 'Crosstour'}
{'Used since': '2012'}
{'Km': '0 Km'}
{'Transmission': 'automatic'}
{'City': 'Cairo'}
{'Color': 'Gold'}
{'Fuel': 'gas'}