-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (22 loc) · 846 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import json
from bs4 import BeautifulSoup as bs
def Scrape(url):
res = requests.get(url)
if res.status_code == 200:
html = res.text
soup = bs(html, 'html.parser')
parentElement = soup.find_all('div', class_="carousel-block-table prakicu-kota")
data_result = []
for element in parentElement:
data = {}
data['kota'] = element.find('h2', class_='kota').text
data['waktu'] = element.find('p').text.replace('\xa0', ' ')
data['cuaca'] = element.find('img')['alt']
data['suhu'] = element.find('h2', class_='heading-md').text
data_result.append(data)
with open('data.json', 'w') as file:
json.dump(data_result, file)
print('done')
url = 'https://www.bmkg.go.id/'
Scrape(url)