【问题标题】:'NoneType' object is not callable : How to parse an XML url link using python?'NoneType' 对象不可调用:如何使用 python 解析 XML url 链接?
【发布时间】:2022-07-19 00:13:56
【问题描述】:

**我正在尝试解析此 XML 链接,但每当我尝试使用 getroot() 函数获取 root 权限时,它都会显示“NoneType”对象不可调用。而且我还想知道如何遍历这个 XML 并打印入口标签内的所有字符串标签。 **

import pandas as pd
import urllib.request
from urllib.request import urlopen
import json
import xml.etree.ElementTree as ET
from bs4 import BeautifulSoup
import requests


url='https://www.omicsdi.org/ws/dataset/pride/PXD002885?debug=false'   // this is the XML url you can refer to
print(url)

response =requests.get(url)   //getting some output as: b'{"database":"Pride","file_versions":[{"files":{"Mgf":["ftp://ftp.pride.ebi.ac.uk/pride/da...........


soup = BeautifulSoup(response.content, 'lxml')
print(soup)                //getting output as: <html><body><p>{"database":"Pride","file_versions":[{"files"................

myroot = soup.getroot()    // getting error: 'NoneType' object is not callable



【问题讨论】:

标签: python xml parsing


【解决方案1】:

b'{"database":"Pride"... 是 JSON,而不是 XML

response = requests.get(url) 
data = response.json()
print(data["database"])  # 'Pride'

【讨论】:

    猜你喜欢
    • 2015-07-03
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 2022-01-03
    相关资源
    最近更新 更多