使用诸如
https://docs.python.org/2/library/xml.etree.elementtree.html
例如,您可以:
import xml.etree.ElementTree as ET
tree = ET.parse('your_xml_file.xml')
enclosures = tree.findall(".//enclosure") # Use the XPath to find all enclosure elements
for enclosure in enclosures:
print(enclosure.attrib)
{'url': 'https://www.nba.com/bucks/sites/bucks/files/styles/media_thumbnail/public/middleton_3point_tw.jpg?itok=eiU05Btp', 'length': '37714', 'type': 'image/jpeg'}
然后可以在
?
例如
url = enclosure.attrib['url'].split('?')[0]
print(url)
输出
https://www.nba.com/bucks/sites/bucks/files/styles/media_thumbnail/public/middleton_3point_tw.jpg