Last active
July 4, 2026 13:04
-
-
Save cmj/501d4941ff0a3748bef43453195797e6 to your computer and use it in GitHub Desktop.
Grab the current hottest temps from popular north american cities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Grab the current hottest temps from somewhat popular (461) north american cities | |
| import cloudscraper | |
| from bs4 import BeautifulSoup | |
| url = "https://www.timeanddate.com/weather/?continent=namerica&sort=6" | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:154.0) Gecko/20100101 Firefox/154.0", | |
| "Referer": "https://www.timeanddate.com/weather/", | |
| } | |
| scraper = cloudscraper.create_scraper( | |
| browser={"browser": "firefox", "platform": "linux", "desktop": True}, | |
| enable_stealth=True, | |
| stealth_options={ | |
| "min_delay": 1.0, | |
| "max_delay": 3.0, | |
| "human_like_delays": True, | |
| "randomize_headers": True, | |
| "browser_quirks": True, | |
| }, | |
| ) | |
| resp = scraper.get(url, headers=headers) | |
| resp.raise_for_status() | |
| soup = BeautifulSoup(resp.text, "html.parser") | |
| table = soup.find("table", class_="zebra fw tb-theme") | |
| results = [] | |
| for row in table.find_all("tr"): | |
| cells = row.find_all("td") | |
| if len(cells) < 6: | |
| continue | |
| city_cell = cells[0] | |
| temp_cell = cells[3] | |
| city_link = city_cell.find("a") | |
| if not city_link: | |
| continue | |
| city = city_link.get_text(strip=True) | |
| temp_text = temp_cell.get_text(strip=True) | |
| temp = temp_text.split()[0] | |
| results.append((city, temp)) | |
| if len(results) == 16: | |
| break | |
| output = " • ".join(f"{city} {temp}°" for city, temp in results) | |
| print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment