I am coding a python code for fun which will find the lowest train ticket price in Eurostar. I am very new to BeautifoulSoup so I do not know much about it. For some reason, the code does not retrieve information from the "ul" tables when theoretically it should.
The code is the following:
input_parser = InputParser()
input_parser.inputDestinations("London","Paris")
input_parser.adults=2
input_parser.inputDates("2021-10-08","2021-10-10")
URL = input_parser.createURL()
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find_all("ul", {"class": "train-table"})
The class input parser basically returns the URL based on the particular data:
class InputParser():
def __init__(self):
self.mapOfDestinations = {"London": "7015400", "Paris": "8727100", "Brussels": "8814001"}
self.destinations = []
self.adults = 0
self.departureDate = ""
self.arrivalDate = ""
def inputDestinations(self, departureDestination, arrivalDestination):
self.destinations.append(self.mapOfDestinations[departureDestination])
self.destinations.append(self.mapOfDestinations[arrivalDestination])
def inputDates(self, departureDate, arrivalDate):
self.departureDate = departureDate
self.arrivalDate = arrivalDate
def inputAdults(self, numberOfAdults):
self.adults = numberOfAdults
def createURL(self):
default_URL = "https://booking.eurostar.com/uk-en/train-search?origin={0}&destination={1}&adult={2}&outbound-date={3}&inbound-date={4}". \
format(self.destinations[0], self.destinations[1], self.adults, self.departureDate, self.arrivalDate)
return default_URL
My code should return the "ul" table linked to the "train-table" but it returns None. Any idea what I am doing wrong?
If you want to look at the source code the code gives the following URL: https://booking.eurostar.com/uk-en/train-search?origin=7015400&destination=8727100&adult=1&outbound-date=2021-10-08&inbound-date=2021-10-10
Thank you so much!