#Coded by Andrew C
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.faredetective.com/farehis...")
soup = BeautifulSoup(page.content, 'html.parser')
title_text = soup.title.get_text()
print(title_text)
print("=" * 40)
print()
Table = soup.find(class_="table table-history")
links_with_text = []
for a in Table.find_all('a', href=True):
if a.text:
links_with_text.append(a['href'])
Data = Table.find_all(class_="text-right")
Prices = [t.get_text() for t in Data]
new_list1 = []
for w in Prices:
w = "".join(c for c in w if c.isdigit())
new_list1.append(w)
Prices = new_list1
new_list2 = []
for w in links_with_text:
res = w.replace('-', ' ')
new_list2.append(res)
links_with_text = new_list2
import pandas as pd
Airlines = pd.DataFrame({
"Flight": [w[55:-12] for w in links_with_text[::2]],
"Prices": Prices
})
print(Airlines)
Смотрите видео Python Bytes - Web Scraping Airline Data BeautifulSoup онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь AC 18 Май 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,212 раз и оно понравилось 28 людям.