我试图找到欧洲之星的最低火车票价。由于某种原因,代码没有检索信息从“ul”表时,理论上应该。
代码如下:
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"})
类输入解析器基本上返回基于特定数据的URL:
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
我的代码应该返回链接到train-table的ul表,但是它返回None。知道我做错了什么吗?
如果您想查看源代码,代码会给出以下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
1条答案
按热度按时间lmvvr0a81#
您看到的数据是从外部URL加载的,因此BeautifulSoup看不到它。但是您可以使用
requests
模块模拟以下查询:印刷品: