I am new to python, I am currently working on a project and would like to ask you I want to use python to read the XML data of this URL
URL: https://thbapp.thb.gov.tw/opendata/vd/one/VDLiveList.xml
Field description: https://thbapp.thb.gov.tw/opendata/vd1.aspx
- Display the name of each VDID
- Read the XML every minute and sum the traffic flow 15 times (I need to analyze the data every 15 minutes)
- When the total data in 15 minutes exceeds 225, a reminder (line bot) will pop up.
- Find a visual kit to visualize the data for easy identification
Below is my code, please provide suggestions, thank you!
import xml.etree.ElementTree as ET
import requests
url = "https://thbapp.thb.gov.tw/opendata/vd/one/VDLiveList.xml"
response = requests.get(url)
tree = ET.fromstring(response.text)
for vdid in tree.findall('VDLive'):
x = vdid.find('VDLive').text
print(x)
How can I get all the data of the specified VDID? For example: VD-11-0020-002-01
import xml.etree.ElementTree as ET
from urllib.request import urlopen
ns = {'xmlns': 'http://traffic.transportdata.tw/standard/traffic/schema/'}
response = urlopen('https://thbapp.thb.gov.tw/opendata/vd/one/VDLiveList.xml')
s = response.read().decode('utf-8')
root = ET.fromstring(s)
for vd in root.findall('.//xmlns:VDLives', ns):
vdid = vd.find('*/xmlns:VDLive/VDID[VD-11-0020-000-01]', ns)
print(vdid)