-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMKG.py
33 lines (32 loc) · 1.44 KB
/
BMKG.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
from lxml import html
import requests
path1 = '//*[@id="meteorologi-geofisika"]/div/div/div[2]/div[2]/div/div[2]/ul/li[2]'
path2 = '//*[@id="meteorologi-geofisika"]/div/div/div[2]/div[2]/div/div[2]/ul/li[3]'
path3 = '//*[@id="meteorologi-geofisika"]/div/div/div[2]/div[2]/div/div[2]/ul/li[4]'
path4 = '//*[@id="meteorologi-geofisika"]/div/div/div[2]/div[2]/div/div[2]/ul/li[5]'
path5 = '//*[@id="meteorologi-geofisika"]/div/div/div[2]/div[2]/div/div[2]/ul/li[6]'
path = '//*[@id="meteorologi-geofisika"]/div/div/div[1]/div[1]/div[2]'
url = ('https://www.bmkg.go.id/')
while True:
pilih = input("input: ")
if pilih == 'cuaca':
response = requests.get(url)
byte_data = response.content
source_code = html.fromstring(byte_data)
tree = source_code.xpath(path)
tr = tree[0].text_content()
print("perkiraan cuaca saat ini: \n",tr)
elif pilih == 'info':
response = requests.get(url)
byte_data = response.content
source_code = html.fromstring(byte_data)
tree = source_code.xpath(path1) #Magnitudo
rt = tree[0].text_content()
rw = source_code.xpath(path2) #Kedalaman
ry = rw[0].text_content()
rx = source_code.xpath(path4) #lokasi
rc = rx[0].text_content()
rv = source_code.xpath(path5)
rb = rv[0].text_content()
print("info gempa terkini")
print("Magnitudo: ",rt, "\nKedalaman: ", ry, "\nLokasi: ", rc, "\nPotensi: ", rb)