有没有一种简单的方法可以将zeep响应转换为json,pandas,xml?

时间:2019-06-25 16:05:38

标签: python json pandas wsdl zeep

我正在使用python 3.6和zeep 3.4.0

Zeep返回原始数据,但我无法将其转换为xml / json / pandas对象。

我尝试使用bs4从text1中获取表格,但不走运。 序列化text1以获取json,也没有运气。

    go build myproject/adapter

我需要从zeep中检索可读的xml或json / pandas表。

3 个答案:

答案 0 :(得分:0)

我自己找到了一种方法:)

from zeep import Client, Settings
from bs4 import BeautifulSoup

settings = Settings(xml_huge_tree=True)

client = Client('http://www.cbr.ru/secinfo/secinfo.asmx?WSDL', settings=settings)
s = '2019-06-21T00:00:00'

with client.settings(raw_response=True):
    result = (client.service.IDRepoRUBXML(s))

#print(dir(result))    
text1 = (result.text)

def escape(t):
    t = t.replace("&","&")
    t1 = t.replace("&lt;","<" )
    t2 = t1.replace( "&gt;",">")
    t3 = t2.replace("&#39;","'")
    t4 = t3.replace("&quot;",'"')
    return t4

m = escape(text1)


#j = parser.feed(m)
if(m is not None):
    soup = BeautifulSoup(m,'lxml')
else:
     print("")

items = soup.find_all('item')

for item in items:
    discounts = item.find_all('dt')
    beg_6d = discounts[0]['beg']
    min_6d = discounts[0]['min']
    max_6d = discounts[0]['max']
    beg7_14 = discounts[1]['beg']
    min7_14 = discounts[1]['min']
    max7_14 = discounts[1]['max']         

    for attr in item.attrs:

        dateredemption = item.attrs['dateredemption']
        em = item.attrs['em']
        isin = item.attrs['isin']
        price = item.attrs['price_fnd']
        regn = item.attrs['regn']

    print(isin,regn,em,dateredemption,price,beg_6d,min_6d,max_6d, beg7_14,min7_14,max7_14) 

答案 1 :(得分:0)

您可以使用Minidom转换为XML。

 @objc func rotateViewPanGesture(_ recognizer: UIPanGestureRecognizer) {
            touchLocation = recognizer.location(in: superview)
            let center = CGRectGetCenter(frame)

            switch recognizer.state {
            case .began:
                deltaAngle = atan2(touchLocation!.y - center.y, touchLocation!.x - center.x) - CGAffineTrasformGetAngle(transform)
                initialBounds = bounds
                initialDistance = CGpointGetDistance(center, point2: touchLocation!)

            case .changed:

                let ang = atan2(touchLocation!.y - center.y, touchLocation!.x - center.x)
                let angleDiff = deltaAngle! - ang

                let a = transform.a
                let b = transform.b
                let c = transform.c
                let d = transform.d

                let sx = sqrt(a * a + b * b)
                let sy = sqrt(c * c + d * d)

                let currentScale = CGPoint(x: sx, y: sy)
                let scale = CGAffineTransform(scaleX: currentScale.x, y: currentScale.y)
                self.transform = scale.rotated(by: -angleDiff)

                layoutIfNeeded()
            case .ended:

              print("end gesture status")
            default:break

            }
        }

答案 2 :(得分:0)

如果您只是想从serialize_object中获取python字典类型,则可以指定所需的类型。

来自zeep导入助手

_json = helpers.serialize_object(zeep_object,dict)