0

This is the website of skyscanner. After selecting flight I want to click on every 'Select button'(for $687) and then go to next page. On next page I want to click down arrow for outbound flight. Then I again I want to click select button ($715) and the again outbound flight arrow. So it goes in loop for all possible searches on all the pages possible.

enter image description here

This is how Downward arrow on next page is

enter image description here

Here is the code I have written so far :

driver = webdriver.Chrome( )

driver.get('https://www.skyscanner.com/transport/flights/nyca/lax/170717/170718/airfares-from-new-york-to-los-angeles-international-in-july-2017.html?adults=1&children=0&adultsv2=1&childrenv2=&infants=0&cabinclass=economy&rtn=1&preferdirects=false&outboundaltsenabled=false&inboundaltsenabled=false&ref=home#results')

while True:
        items=driver.find_element_by_class_name("fss-bpk-button expand-cba select-action")
        for i, item in enumerate(items):
            driver.find_element_by_class_name("fss-bpk-button expand-cba select-action").click()
              for j, item2 in item
                  driver.find_element_by_class_name("leg-summary-container clearfix").click()

I also tried following but none worked:

 links = [link.get_attribute('href') for link in driver.find_element_by_class_name("fss-bpk-button expand-cba select-action")]
    for link in links:
        driver.get(link)

1 Answer 1

0

Your second code should work after some changes:

links = [link.get_attribute('href') for link in driver.find_elements_by_css_selector("a.fss-bpk-button.expand-cba.select-action")]

Note that

  1. To get list of elements you should use find_elements_...() instead of find_element_...()
  2. Compound class names not allowed, so you might use search by CSS selector or XPath instead of search by class name if you want to use multiple class names to locate required elements
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much ! I am completely new to python so learning a lot! How should I loop it between the pages ? I don't understand it
In the same way you tried: for link in links: driver.get(link)... You got the list of links. You can navigate to each page to make required actions in a loop\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.