Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No results for multi-city #2

Open
deepernewbie opened this issue May 24, 2024 · 4 comments
Open

No results for multi-city #2

deepernewbie opened this issue May 24, 2024 · 4 comments

Comments

@deepernewbie
Copy link

deepernewbie commented May 24, 2024

from fast_flights import FlightData, Passengers, create_filter, get_flights

# Create a new filter
filter = create_filter(
    flight_data=[
        # Include more if it's not a one-way trip
        FlightData(
            date='2024-06-19',  # Date of departure
            from_airport="IST",
            to_airport="LAX"
        ),
        FlightData(
            date='2024-07-09',  # Date of departure
            from_airport="NYC",
            to_airport="IST"
        ),
        # ... include more for round trips and multi-city trips
    ],
    trip="multi-city",  # Trip (round-trip, one-way, multi-city)
    seat="economy",  # Seat (economy, premium-economy, business or first)
    passengers=Passengers(
        adults=1,
        children=0,
        infants_in_seat=0,
        infants_on_lap=0
    ),
)

result = get_flights(filter)

# The price is currently... low/typical/high
print("The price is currently", result.current_price)

# Display the first flight
print(result.flights[0])

returns no flights however if I manually use

https://www.google.com/travel/flights?tfs=GhoSCjIwMjQtMDYtMTlqBRIDSVNUcgUSA0xBWBoaEgoyMDI0LTA3LTA5agUSA05ZQ3IFEgNJU1RCAQFIAZgBAw%3D%3D&hl=en&tfu=EgQIABABIgA

which is the generated link there are flights

I think the problem is results take about 2-3 secs to populate but response.get returns almost immediately without waiting

@AWeirdDev
Copy link
Owner

Could you please clarify the issue?

@deepernewbie deepernewbie changed the title No results for multi-c No results for multi-city May 24, 2024
@AWeirdDev
Copy link
Owner

Hi there,

This is due to the EU Consent Request page. (See #1).

As mentioned in the issue by IHannes, they added a cookie and everything seems to be working fine.

We can add the CONSENT cookie and theoretically it should be working as expected.

cookies = { "CONSENT": "YES+" }

# tag: v0.3
get_flights(filter, cookies=cookies)

Refer to stackoverflow.com • bypassing-eu-consent-request for more.

P.S. I'm not aware of the "EU Consent Request" when developing this project since I'm not in the region. I'm deeply sorry for my oversight and any inconvenience caused.

Regards,
AWeirdDev

@deepernewbie
Copy link
Author

No this is not about the cookies I know about this because I debugged into the return request and get the html text and rendered it in

https://htmledit.squarefree.com/

it renders find but there are no flights and blue color flow indicating search is continuing is running left to right
I believe this is about requests.get does not wait for an object to load and returns immediately If I use the url generated by your code on some other google flight scraper that uses selenium It works because they added something like as follows

driver.get(url)
WebDriverWait(driver, timeout=10).until(lambda d: len(_get_flight_elements(d)) > 100)
results = _get_flight_elements(driver)

where

def _get_flight_elements(driver):
    return driver.find_element(by=By.XPATH, value='//body[@id = "yDmH0d"]').text.split('\n')

@AWeirdDev
Copy link
Owner

Hi again,

Ahh, I understand the context now.

Both round-trip and one-way works fine, but not multi-city, as cited here:

MULTI_CITY = 3; // not implemented

I assume that multi-city loads custom Javascript that cannot be handled by requests. It requires something like puppeteer or playwright.

Just to keep this package light, we can use the try.playwright.tech API to scrape the flights. If you'd like me to implement this, please let me know. Alternatively, you can try the code below before v0.4 rolls out:

API

requests.post(
    "https://try.playwright.tech/service/control/run",
    headers={ "User-Agent": "... your user agent" },
    json={
        "code": "# some playwright python code",
        "language": "python"
    }
)

Sincerely,
AWeirdDev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants