Web scraping google flight pricesextract label value for checkbox input object with beautiful soup instead of mechanize in pythonUse the contents of a div as more Beautful Soup inputAirline Price Scraping with PythonHow can I web-scrape with Python when the HTML doesn't change?Walmart Price Scraping with Python 3Scraping Flipkart webpage using beautifulsoupHow Can I Scrape Data From Websites Don't Return Simple HTMLScraping Table using Python and SeleniumHow to scrape a google search results page?Querying <div class=“name”> in Python

Why is Robin Hood French in Shrek?

Employer says they want Quality & Quantity, but only pays bonuses based on the latter

Identifying root parents and all their children in trees

Is there a name for the phenomenon of false positives counterintuitively outstripping true positives

How can a signal be both periodic and random?

What is the purpose of polls published by the organization that they are asking about which have leading/confusing questions?

Program to print the multiple occurrence of numbers in a list

I don't know the meaning of this piece of code in C++

Could the principle of owls' silent flight be used for stealth aircraft?

Do you celebrate paying your mortgage off with colleagues?

Covering an 8x8 grid with X pentominoes

What is the difference between democracy and ochlocracy?

How to delete music as it's being played

A pencil in a beaker of water

Can the Infinity Stones be destroyed?

What would you do? Different results than what is reported

Is This Constraint Convex?

Moisture leaking out of chip in floor tile

Did the Allies reverse the threads on secret microfilm-hiding buttons to thwart the Germans?

Extract lines from files with names begining with given letter

Do players roll their own die?

Is there any physical evidence for motion?

Would there be a difference between boiling whole black peppercorns or fine ground black pepp in a stew?

How to make black peppercorns extremely fine?



Web scraping google flight prices


extract label value for checkbox input object with beautiful soup instead of mechanize in pythonUse the contents of a div as more Beautful Soup inputAirline Price Scraping with PythonHow can I web-scrape with Python when the HTML doesn't change?Walmart Price Scraping with Python 3Scraping Flipkart webpage using beautifulsoupHow Can I Scrape Data From Websites Don't Return Simple HTMLScraping Table using Python and SeleniumHow to scrape a google search results page?Querying <div class=“name”> in Python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









5

















I am trying to learn to use the python library BeautifulSoup, I would like to, for example, scrape a price of a flight on Google Flights.
So I connected to Google Flights, for example at this link, and I want to get the cheapest flight price.



So I would get the value inside the div with this class "gws-flights-results__itinerary-price" (as in the figure).



figure example



Here is the simple code I wrote:



from bs4 import BeautifulSoup
import urllib.request

url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
page = urllib.request.urlopen(url)
soup = BeautifulSoup(page, 'html.parser')
div = soup.find('div', attrs='class': 'gws-flights-results__itinerary-price')


But the resulting div has class NoneType.



I also try with



find_all('div') 


but within all the div I found in this way, there was not the div I was interested in.
Can someone help me?










share|improve this question


































    5

















    I am trying to learn to use the python library BeautifulSoup, I would like to, for example, scrape a price of a flight on Google Flights.
    So I connected to Google Flights, for example at this link, and I want to get the cheapest flight price.



    So I would get the value inside the div with this class "gws-flights-results__itinerary-price" (as in the figure).



    figure example



    Here is the simple code I wrote:



    from bs4 import BeautifulSoup
    import urllib.request

    url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
    page = urllib.request.urlopen(url)
    soup = BeautifulSoup(page, 'html.parser')
    div = soup.find('div', attrs='class': 'gws-flights-results__itinerary-price')


    But the resulting div has class NoneType.



    I also try with



    find_all('div') 


    but within all the div I found in this way, there was not the div I was interested in.
    Can someone help me?










    share|improve this question






























      5












      5








      5


      1






      I am trying to learn to use the python library BeautifulSoup, I would like to, for example, scrape a price of a flight on Google Flights.
      So I connected to Google Flights, for example at this link, and I want to get the cheapest flight price.



      So I would get the value inside the div with this class "gws-flights-results__itinerary-price" (as in the figure).



      figure example



      Here is the simple code I wrote:



      from bs4 import BeautifulSoup
      import urllib.request

      url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
      page = urllib.request.urlopen(url)
      soup = BeautifulSoup(page, 'html.parser')
      div = soup.find('div', attrs='class': 'gws-flights-results__itinerary-price')


      But the resulting div has class NoneType.



      I also try with



      find_all('div') 


      but within all the div I found in this way, there was not the div I was interested in.
      Can someone help me?










      share|improve this question

















      I am trying to learn to use the python library BeautifulSoup, I would like to, for example, scrape a price of a flight on Google Flights.
      So I connected to Google Flights, for example at this link, and I want to get the cheapest flight price.



      So I would get the value inside the div with this class "gws-flights-results__itinerary-price" (as in the figure).



      figure example



      Here is the simple code I wrote:



      from bs4 import BeautifulSoup
      import urllib.request

      url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
      page = urllib.request.urlopen(url)
      soup = BeautifulSoup(page, 'html.parser')
      div = soup.find('div', attrs='class': 'gws-flights-results__itinerary-price')


      But the resulting div has class NoneType.



      I also try with



      find_all('div') 


      but within all the div I found in this way, there was not the div I was interested in.
      Can someone help me?







      python web-scraping beautifulsoup






      share|improve this question
















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 23:00









      Hoppeduppeanut

      6042 gold badges12 silver badges18 bronze badges




      6042 gold badges12 silver badges18 bronze badges










      asked Mar 28 at 21:39









      Andrea BarnabòAndrea Barnabò

      11010 bronze badges




      11010 bronze badges

























          3 Answers
          3






          active

          oldest

          votes


















          5


















          Looks like javascript needs to run so use a method like selenium



          from selenium import webdriver
          url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
          driver = webdriver.Chrome()
          driver.get(url)
          print(driver.find_element_by_css_selector('.gws-flights-results__cheapest-price').text)
          driver.quit()





          share|improve this answer


























          • Thanks for your answer! I did not consider Selenium. It works, thanks.

            – Andrea Barnabò
            Mar 28 at 23:13



















          2


















          Its great that you are learning web scrapping! The reason you are getting NoneType as a result is because the website that you are scraping loads content dynamically. When requests library fetches the url it only contains javascript. and the div with this class "gws-flights-results__itinerary-price" isn't rendered yet! So it won't be possible by the scraping approach you are using to scrape this website.



          However you can use other methods such as fetching the page using tools such as selenium or splash to render the javascript and then parse the content.






          share|improve this answer




























          • Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

            – Andrea Barnabò
            Mar 30 at 18:30


















          1


















          BeautifulSoup is a great tool for extracting part of HTML or XML, but here it looks like you only need to get the url to another GET-request for a JSON object.



          (I am not by a computer now, can update with an example tomorrow.)






          share|improve this answer


























          • Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

            – Andrea Barnabò
            Mar 28 at 23:14












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407247%2fweb-scraping-google-flight-prices%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown


























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5


















          Looks like javascript needs to run so use a method like selenium



          from selenium import webdriver
          url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
          driver = webdriver.Chrome()
          driver.get(url)
          print(driver.find_element_by_css_selector('.gws-flights-results__cheapest-price').text)
          driver.quit()





          share|improve this answer


























          • Thanks for your answer! I did not consider Selenium. It works, thanks.

            – Andrea Barnabò
            Mar 28 at 23:13
















          5


















          Looks like javascript needs to run so use a method like selenium



          from selenium import webdriver
          url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
          driver = webdriver.Chrome()
          driver.get(url)
          print(driver.find_element_by_css_selector('.gws-flights-results__cheapest-price').text)
          driver.quit()





          share|improve this answer


























          • Thanks for your answer! I did not consider Selenium. It works, thanks.

            – Andrea Barnabò
            Mar 28 at 23:13














          5














          5










          5









          Looks like javascript needs to run so use a method like selenium



          from selenium import webdriver
          url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
          driver = webdriver.Chrome()
          driver.get(url)
          print(driver.find_element_by_css_selector('.gws-flights-results__cheapest-price').text)
          driver.quit()





          share|improve this answer














          Looks like javascript needs to run so use a method like selenium



          from selenium import webdriver
          url = 'https://www.google.com/flights?hl=it#flt=/m/07_pf./m/05qtj.2019-04-27;c:EUR;e:1;sd:1;t:f;tt:o'
          driver = webdriver.Chrome()
          driver.get(url)
          print(driver.find_element_by_css_selector('.gws-flights-results__cheapest-price').text)
          driver.quit()






          share|improve this answer













          share|improve this answer




          share|improve this answer










          answered Mar 28 at 21:49









          QHarrQHarr

          55.8k9 gold badges30 silver badges55 bronze badges




          55.8k9 gold badges30 silver badges55 bronze badges















          • Thanks for your answer! I did not consider Selenium. It works, thanks.

            – Andrea Barnabò
            Mar 28 at 23:13


















          • Thanks for your answer! I did not consider Selenium. It works, thanks.

            – Andrea Barnabò
            Mar 28 at 23:13

















          Thanks for your answer! I did not consider Selenium. It works, thanks.

          – Andrea Barnabò
          Mar 28 at 23:13






          Thanks for your answer! I did not consider Selenium. It works, thanks.

          – Andrea Barnabò
          Mar 28 at 23:13














          2


















          Its great that you are learning web scrapping! The reason you are getting NoneType as a result is because the website that you are scraping loads content dynamically. When requests library fetches the url it only contains javascript. and the div with this class "gws-flights-results__itinerary-price" isn't rendered yet! So it won't be possible by the scraping approach you are using to scrape this website.



          However you can use other methods such as fetching the page using tools such as selenium or splash to render the javascript and then parse the content.






          share|improve this answer




























          • Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

            – Andrea Barnabò
            Mar 30 at 18:30















          2


















          Its great that you are learning web scrapping! The reason you are getting NoneType as a result is because the website that you are scraping loads content dynamically. When requests library fetches the url it only contains javascript. and the div with this class "gws-flights-results__itinerary-price" isn't rendered yet! So it won't be possible by the scraping approach you are using to scrape this website.



          However you can use other methods such as fetching the page using tools such as selenium or splash to render the javascript and then parse the content.






          share|improve this answer




























          • Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

            – Andrea Barnabò
            Mar 30 at 18:30













          2














          2










          2









          Its great that you are learning web scrapping! The reason you are getting NoneType as a result is because the website that you are scraping loads content dynamically. When requests library fetches the url it only contains javascript. and the div with this class "gws-flights-results__itinerary-price" isn't rendered yet! So it won't be possible by the scraping approach you are using to scrape this website.



          However you can use other methods such as fetching the page using tools such as selenium or splash to render the javascript and then parse the content.






          share|improve this answer
















          Its great that you are learning web scrapping! The reason you are getting NoneType as a result is because the website that you are scraping loads content dynamically. When requests library fetches the url it only contains javascript. and the div with this class "gws-flights-results__itinerary-price" isn't rendered yet! So it won't be possible by the scraping approach you are using to scrape this website.



          However you can use other methods such as fetching the page using tools such as selenium or splash to render the javascript and then parse the content.







          share|improve this answer















          share|improve this answer




          share|improve this answer








          edited Mar 28 at 22:15

























          answered Mar 28 at 22:06









          Hoossain KhanHoossain Khan

          212 bronze badges




          212 bronze badges















          • Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

            – Andrea Barnabò
            Mar 30 at 18:30

















          • Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

            – Andrea Barnabò
            Mar 30 at 18:30
















          Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

          – Andrea Barnabò
          Mar 30 at 18:30





          Hi Khan, thanks for your comment. I didn't know about splash. I will look forward to it.

          – Andrea Barnabò
          Mar 30 at 18:30











          1


















          BeautifulSoup is a great tool for extracting part of HTML or XML, but here it looks like you only need to get the url to another GET-request for a JSON object.



          (I am not by a computer now, can update with an example tomorrow.)






          share|improve this answer


























          • Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

            – Andrea Barnabò
            Mar 28 at 23:14















          1


















          BeautifulSoup is a great tool for extracting part of HTML or XML, but here it looks like you only need to get the url to another GET-request for a JSON object.



          (I am not by a computer now, can update with an example tomorrow.)






          share|improve this answer


























          • Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

            – Andrea Barnabò
            Mar 28 at 23:14













          1














          1










          1









          BeautifulSoup is a great tool for extracting part of HTML or XML, but here it looks like you only need to get the url to another GET-request for a JSON object.



          (I am not by a computer now, can update with an example tomorrow.)






          share|improve this answer














          BeautifulSoup is a great tool for extracting part of HTML or XML, but here it looks like you only need to get the url to another GET-request for a JSON object.



          (I am not by a computer now, can update with an example tomorrow.)







          share|improve this answer













          share|improve this answer




          share|improve this answer










          answered Mar 28 at 22:00









          PunnerudPunnerud

          1,34414 silver badges20 bronze badges




          1,34414 silver badges20 bronze badges















          • Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

            – Andrea Barnabò
            Mar 28 at 23:14

















          • Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

            – Andrea Barnabò
            Mar 28 at 23:14
















          Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

          – Andrea Barnabò
          Mar 28 at 23:14





          Thanks for your answer, I resolved my question with the code posted by QHarr.Thanks again.

          – Andrea Barnabò
          Mar 28 at 23:14


















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407247%2fweb-scraping-google-flight-prices%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown









          Popular posts from this blog

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?