4


我正在使用 suds 库从网络服务中获取产品列表。

这是一个示例代码:

from suds.client import Client
url = 'WSDLURL'
client = Client(url)
result = client.service.Research('value')

结果包含:

(ArrayOfProducts){
   Product[] = 
      (Product){
         Id = 218
         Code = "C024"
         Name = "test2"
         Avaiable = True
         UrlDownload = None
         MetaData = 
            (ArrayOfMetaData){
               MetaData[] = 
                  (MetaData){
                     CoderepositoryISO = "16701"
                     Title = "1ST"
                  },
            }
      },
      (Product){
         Id = 219
         Code = "C025"
         Name = "test3"
         Avaiable = True
         UrlDownload = None
         MetaData = 
            (ArrayOfMetaData){
               MetaData[] = 
                  (MetaData){
                     CoderepositoryISO = "16702"
                     Title = "2ND"
                  },
            }
      },
...

在 python 或 suds 中,有一种方法可以使用 for? 直接访问产品上包含的循环数据。(例如:Product.Id、Product.Code 等)

4

1 回答 1

5

完美......感谢JF Sebastian,我找到了正确的方法......这是工作代码:

from suds.client import Client
url = 'wsdl'
client = Client(url)
html_out = ""
result = client.service.Research('a')
for p in result.Product:
   print p.Id
   print p.Name
于 2010-12-16T14:58:42.437 回答