Crawling weather information from weather website

+2 Matthijs Koningstein · January 21, 2016
Hi all,

as I´m fairly new to programming, but decided it would be much cheaper and much much more fun to build and program my own aquarium computer, I´ve been learning each and every day, with a whole lot of fun. 

Now I´m at the point where I´d like to get weather information from a website of my choosing, and import them in my gui. 

Like I said, I´m new to programming, so I´d like some pointers on how to get the data as shown in below text

<span class="weather-map__table-cell margin-top-10">
            <span class="weather-map__label">Zonneschijn</span>
            20%
          </span>

The 20% is what I´m looking to import. 

Any help is much appreciated. 

Thanks

Matthijs

Post a Reply

Replies

Oldest  Newest  Rating
+2 Mustafa Fakhrualdin · January 22, 2016
You first have to import modules 
import requests
from bs4 import BeautifulSoup

then You have to target the website
url = "http:/sjijdsisdjidsji.com" 
source_code = requests.get(url)
html_code = source_code.text


Now that we gottin into the website. we are ready to take information

soup = BeautifulSoup(html_code, "html.parser")
result = soupfindAll('span', {"class": 'weather-map__table-cell margin-top-10'})
print(result.contents[0]
0 john lalani · January 22, 2016
Just make sure you stay in the zone of "permission" when it comes to the legality of it. If it's data that can be browsed through with a popular browser & not used for commercial purposes it's fine. https://www.promptcloud.com/blog/is-crawling-legal/

As in for Mustafa Fakhrualdin's code, typos:


result = soup.findAll('span', {"class": 'weather-map__table-cell margin-top-10'})
print (result.contents[0])

.stripped_strings to get results from contents that contain pictures. The docs will surely help for other problems.
0 Matthijs Koningstein · January 22, 2016
The legality issue is something I haven't thought of yet. Thanks for pointing me towards potential issues. 

As for the code: 

(result.contents[0]) was what I was looking for. The rest of the code I'd gotten from one of the tutorials. Next time I'll post what I've gotten sofar, That'll help for sure.

Thanks.
  • 1

Python

107,202 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator