Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fadb061

Browse files
Add files via upload
1 parent 865d971 commit fadb061

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from bs4 import BeautifulSoup
2+
import requests
3+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
4+
5+
#function for getting the updates and fetching the only required output
6+
def weather(city):
7+
city=city.replace(" ","+")
8+
res = requests.get(f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8',headers=headers)
9+
print("Searching......\n")
10+
soup = BeautifulSoup(res.text,'html.parser')
11+
location = soup.select('#wob_loc')[0].getText().strip()
12+
time = soup.select('#wob_dts')[0].getText().strip()
13+
info = soup.select('#wob_dc')[0].getText().strip()
14+
weather = soup.select('#wob_tm')[0].getText().strip()
15+
#printing all the output
16+
print(location)
17+
print(time)
18+
print(info)
19+
print(weather+"°C")
20+
21+
#getting the name of city from user
22+
city=input("Enter the Name of Any City >> ")
23+
city=city+" weather"
24+
weather(city)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /