我正在尝试将以下网站转换为数据框架,以便处理数据:https://www.ifsqn.com/forum/index.php/rss/forums/4-food-safety-quality-discussion/
无论我在网上看到什么地方,我都只看到如何将XML文件转换为数据帧。我尝试了以下方法,但它不起作用,因为它不是XML文件。我可以自己做熊猫部分,但首先,需要有数据来处理
import requests
import xml.etree.ElementTree as ET
headers = {'User-Agent': 'Mozilla/5.0'}
r = requests.get("https://www.ifsqn.com/forum/index.php/rss/forums/4-food-safety-quality-discussion/",headers=headers)
c = r.content
root = ET.parse(r).getroot()
print(root)
我在这里遗漏了哪些步骤来将XML转换为可读格式,从而将数据转换为数据帧
非常感谢您的任何意见
要解析的XML是RSS,因为它具有特定的格式,所以可以使用解析RSS提要的python库(feedparser作为示例)
另一种方法是自己将XML解析为某种结构,该结构可用于构造数据帧Example here
编辑:
现在我看到您在以下行中传递了
r
而不是c
:相关问题 更多 >
编程相关推荐