Склейка одного слова с каждым элементом списка с помощью .join()
Нужно склеить с помощью .join() цену и валюту(например 7000 и руб.)
7000 - hotel_price
руб. - hotel_price2
из за того что цен много то он склеивает только последнюю цену, а мне нужно все
import requests
import lxml
from bs4 import BeautifulSoup
import csv
def get_data(url):
headers = {
'User Agent': 'Mozilla / 5.0(WindowsNT10.0; Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 110.0.0.0 Safari / 537.36'
}
req = requests.get(url=url)
#with open('index.html', 'w', encoding='utf8') as file:
#file.write(req.text)
soup = BeautifulSoup(req.text, 'lxml')
hotel_cards = soup.find_all('li', class_='item')
#print(hotel_cards)
for hotel_url in hotel_cards:
hotel_url = 'https://101hotels.com' + hotel_url.find('a').get('href')
#print(hotel_url)
for title_hotels in hotel_cards:
title_hotels = title_hotels.find('a').text
#print(title_hotels)
for hotel_price in hotel_cards:
hotel_price = hotel_price.find('span', class_='price-highlight').text.strip()
print(hotel_price)
for hotel_price2 in hotel_cards:
hotel_price2 = hotel_price2.find('span', class_='currency').text.strip()
print(hotel_price2)
hotel_price_result_str = " ".join()
def main():
get_data('https://101hotels.com/main/cities/yuzhno-sakhalinsk')
if __name__ == '__main__':
main()
Источник: Stack Overflow на русском