omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    What do I look for when wanting to scrape a certain thing?

    Pythonista
    3
    7
    3678
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • InAPickle
      InAPickle last edited by

      import bs4, requests
      
      def get_beautiful_soup(url):
          return bs4.BeautifulSoup(requests.get(url).text)
      
      soup = get_beautiful_soup('http://www.weatherbug.com')
      
      print(soup.get_text())
      
      

      Ok so as of now, in the script above I have made you use weather bug to find the weather in your local area, and your area and weather should appear at the top. After looking into the buetiful soup 4 documentation, I see that you are able to extract certain information. The way it is explained on the Documentation is that you can use "for link in soup.find_all('a'):" to find all of the "<a>" 's in the website. My problem is that every location has a different name, so I can't just tell it to look for one because that won't find your location. If you know what to do please help, I will continue to do research on this.

      1 Reply Last reply Reply Quote 0
      • Webmaster4o
        Webmaster4o last edited by

        This is not really a pythonista-specific question, you might have more luck in stackoverflow. It's a far larger community, you'll likely get an answer within an hour.

        1 Reply Last reply Reply Quote 0
        • InAPickle
          InAPickle last edited by

          Well there has to be someone in this community who knows how.

          1 Reply Last reply Reply Quote 0
          • Webmaster4o
            Webmaster4o last edited by Webmaster4o

            Weatherbug is not a simple site, it has lots of fancy CSS and JavaScript. For someone with your apparent skill level, don't try it. Use a pre-built Python library for weather forecasts, like this one which I found with a quick Google search. The location module can give you the device's latitude / longitude.

            1 Reply Last reply Reply Quote 0
            • Webmaster4o
              Webmaster4o last edited by Webmaster4o

              If you download the previously linked library to site_packages, this code will get you the current weather at a location, as an example

              import location, forecastio
              
              api_key = 'bb17c2f14b8e3e00d543485185af019c'
              
              location_data = location.get_location()
              lat = location_data['latitude']
              lon = location_data['longitude']
              
              forecast = forecastio.load_forecast(api_key, lat, lon)
              weather = forecast.currently()
              
              print weather.summary
              

              Please get your own API key instead of continuing to use mine once you verify that it works. Read the documentation for forecastio for more complex uses.

              1 Reply Last reply Reply Quote 0
              • InAPickle
                InAPickle last edited by

                Ok, thanks a lot

                1 Reply Last reply Reply Quote 0
                • ccc
                  ccc last edited by

                  https://github.com/coomlata1/pythonista-scripts And https://github.com/cclauss/weather_where_you_are Might help.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors