python xml 响应断言

XML 断言

from requests_xml import XMLSession
session = XMLSession()
r = session.get('https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss')
print(r.xml.links)

XPath 断言

from requests_xml import XMLSession
session = XMLSession()
r = session.get('https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss')
item = r.xml.xpath('//item', first=True)
print(item.text)

XML 解析

import xml.etree.ElementTree as ET
root = ET.fromstring(countrydata)
root.findall(".")
root.findall("./country/neighbor")
root.findall(".//year/..[@name='Singapore']")
root.findall(".//*[@name='Singapore']/year")
root.findall(".//neighbor[2]")
posted @ 2023-06-05 14:30  来了发发发  阅读(15)  评论(0)    收藏  举报