我想采用网络托管的xml播客文件并循环浏览,将所有标题放入与guid匹配的txt文件中,即abcd.mp3.txt
(或abcd.txt
)将包含{{ 1}}
This is the title
我已经回答了问题并查看了xmlstarlet,xmlgrep,xmlsh。然后就像Osmosis这样的东西看起来很强大但需要节点并且缺乏实用的文档。理想情况下使用尽可能少的外部依赖项(尽管安装了Python 3.6)。
在一个上午过后,我开始怀疑自己是否过度思考/使事情复杂化。任何指针都赞赏。
答案 0 :(得分:0)
好吧,在多次弄乱样式表后,我偶然发现了BeautifulSoup。
答案很简单(HT到this guide)
pip install bs4
pip install lxml
然后
#! /usr/bin/env python3
from bs4 import BeautifulSoup
import requests
url = 'http://www.example.com/somepodcast.xml'
content = requests.get(url).content
soup = BeautifulSoup(content,'lxml') # choose lxml parser
titles = soup.find_all('title')
for title in titles:
print(title) # or do whatever.
感谢其他建议,但这对我来说不会影响xpath,正则表达式等。