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 f62ded0

Browse files
Merge pull request #540 from neelshah2409/main
Weather Updates (Web Scrapping)
2 parents d875a92 + fda2e1b commit f62ded0

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed
14.6 KB
Loading[フレーム]
14.3 KB
Loading[フレーム]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Weather Updates
2+
3+
## Aim/Purpose
4+
To fetch weather updates of any city
5+
## Short description of package/script
6+
7+
- Here we will fetch the weather updates from the url of the weather website through requests and getting the formatted output using bs4 library.Here we can fetch the data of any city.
8+
- List out the libraries imported are bs4 and requests.
9+
10+
## Workflow
11+
Here we need to install the libraries first then we need the google website url for fetching the data and then using the request we will fetch all the data and then with bs4 we will get only the required data in proper format.
12+
## Setup instructions
13+
14+
We just need to get the url for fetching the weather updates and paste it in the script and then using bs4 we will get the only necessary things in the output.
15+
16+
17+
## Output
18+
19+
![image](Images/output_1(weather).png)
20+
![image](Images/output_2(weather).png)
21+
22+
## Author(s)
23+
24+
Neel Shah
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Libraries used : requests , bs4
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 によって変換されたページ (->オリジナル) /