2011-04-06 40 views
-4
------------------------------------------------------------------------------------- Suds (https://fedorahosted.org/suds/) version: 0.3.9 (beta) build: R658-20100210 

Service (ndfdXML) tns="http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl" Prefixes (2) 
     ns0 = "http://schemas.xmlsoap.org/soap/encoding/" 
     ns1 = "http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd" Ports (1): 
     (ndfdXMLPort) 
     Methods (12): 
      ***CornerPoints***(ns1:sectorType sector,) 
      ***GmlLatLonList***(ns1:listLatLonType listLatLon, xs:dateTime requestedTime, ns1:featureTypeType featureType, ns1:weatherParametersType weatherParameters,) 
      ***GmlTimeSeries***(ns1:listLatLonType listLatLon, xs:dateTime startTime, xs:dateTime endTime, ns1:compTypeType compType, ns1:featureTypeType featureType, xs:string propertyName,) 
      ***LatLonListCityNames***(ns1:displayLevelType displayLevel,) 
      ***LatLonListLine***(xs:decimal endPoint1Lat, xs:decimal endPoint1Lon, xs:decimal endPoint2Lat, xs:decimal endPoint2Lon,) 
      ***LatLonListSquare***(xs:decimal centerPointLat, xs:decimal centerPointLon, xs:decimal distanceLat, xs:decimal distanceLon, xs:decimal resolution,) 
      ***LatLonListSubgrid***(xs:decimal lowerLeftLatitude, xs:decimal lowerLeftLongitude, xs:decimal upperRightLatitude, xs:decimal upperRightLongitude, xs:decimal resolution,) 
      ***LatLonListZipCode***(ns1:zipCodeListType zipCodeList,) 
      **NDFDgen**(xs:decimal latitude, xs:decimal longitude, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters,) 
      ***NDFDgenByDay***(xs:decimal latitude, xs:decimal longitude, xs:date startDate, xs:integer numDays, ns1:formatType format,) 
      ***NDFDgenByDayLatLonList***(ns1:listLatLonType listLatLon, xs:date startDate, xs:integer numDays, ns1:formatType format,) 
      ***NDFDgenLatLonList***(ns1:listLatLonType listLatLon, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters,) 
     Types (60): 
      ns0:Array 
      ns0:ENTITIES 
      ns0:ENTITY 
      ns0:ID 
      ns0:IDREF 
      ns0:IDREFS 
      ns0:NCName 
      ns0:NMTOKEN 
      ns0:NMTOKENS 
      ns0:NOTATION 
      ns0:Name 
      ns0:QName 
      ns0:Struct 
      ns0:anyURI 
      ns0:arrayCoordinate 
      ns0:base64 
      ns0:base64Binary 
      ns0:boolean 
      ns0:byte 
      ns1:compTypeType 
      ns0:date 
      ns0:dateTime 
      ns0:decimal 
      ns1:displayLevelType 
      ns0:double 
      ns0:duration 
      ns1:featureTypeType 
      ns0:float 
      ns1:formatType 
      ns0:gDay 
      ns0:gMonth 
      ns0:gMonthDay 
      ns0:gYear 
      ns0:gYearMonth 
      ns0:hexBinary 
      ns0:int 
      ns0:integer 
      ns0:language 
      ns1:latLonPairType 
      ns1:listCityNamesType 
      ns1:listLatLonType 
      ns0:long 
      ns0:negativeInteger 
      ns0:nonNegativeInteger 
      ns0:nonPositiveInteger 
      ns0:normalizedString 
      ns0:positiveInteger 
      ns1:productType 
      ns1:sectorType 
      ns0:short 
      ns0:string 
      ns0:time 
      ns0:token 
      ns0:unsignedByte 
      ns0:unsignedInt 
      ns0:unsignedLong 
      ns0:unsignedShort 
      ns1:weatherParametersType 
      ns1:zipCodeListType 
      ns1:zipCodeType 
------------------------------------------------------------------------------------------- 
+0

请正确格式化您的代码!除此之外:提供你迄今为止所尝试的信息......我们不能猜测你迄今为止所做的努力,从现有的东西中获得帮助比从头开始获得帮助要容易得多。 – 2011-04-06 02:39:01

+0

除此之外呢?你为什么要解析* this *输出? Suds提供了反思相关结果的足够方法。你的特定用例是什么? – 2011-04-06 02:40:29

+1

欢迎来到StackOverflow!我已将格式化问题的文本给你。你能否更详细地解释你遇到的实际问题?有关提问问题的更多提示,请查阅[FAQ](http://stackoverflow.com/faq)。 – Johnsyweb 2011-04-06 03:30:04

回答

0
import re 
text='''Service (ndfdXML) tns="http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl" Prefixes (2) ns0 = "http://schemas.xmlsoap.org/soap/encoding/" ns1 = "http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd" Ports (1): (ndfdXMLPort) Methods (12): CornerPoints(ns1:sectorType sector,) GmlLatLonList(ns1:listLatLonType listLatLon, xs:dateTime requestedTime, ns1:featureTypeType featureType, ns1:weatherParametersType weatherParameters,) GmlTimeSeries(ns1:listLatLonType listLatLon, xs:dateTime startTime, xs:dateTime endTime, ns1:compTypeType compType, ns1:featureTypeType featureType, xs:string propertyName,) LatLonListCityNames(ns1:displayLevelType displayLevel,) LatLonListLine(xs:decimal endPoint1Lat, xs:decimal endPoint1Lon, xs:decimal endPoint2Lat, xs:decimal endPoint2Lon,) LatLonListSquare(xs:decimal centerPointLat, xs:decimal centerPointLon, xs:decimal distanceLat, xs:decimal distanceLon, xs:decimal resolution,) LatLonListSubgrid(xs:decimal lowerLeftLatitude, xs:decimal lowerLeftLongitude, xs:decimal upperRightLatitude, xs:decimal upperRightLongitude, xs:decimal resolution,) LatLonListZipCode(ns1:zipCodeListType zipCodeList,) NDFDgen(xs:decimal latitude, xs:decimal longitude, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters,) NDFDgenByDay(xs:decimal latitude, xs:decimal longitude, xs:date startDate, xs:integer numDays, ns1:formatType format,) NDFDgenByDayLatLonList(ns1:listLatLonType listLatLon, xs:date startDate, xs:integer numDays, ns1:formatType format,) NDFDgenLatLonList(ns1:listLatLonType listLatLon, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters,) Types (60): ns0:Array ns0:ENTITIES ns0:ENTITY ns0:ID ns0:IDREF ns0:IDREFS ns0:NCName ns0:NMTOKEN ns0:NMTOKENS ns0:NOTATION ns0:Name ns0:QName ns0:Struct ns0:anyURI ns0:arrayCoordinate ns0:base64 ns0:base64Binary ns0:boolean ns0:byte ns1:compTypeType ns0:date ns0:dateTime ns0:decimal ns1:displayLevelType ns0:double ns0:duration ns1:featureTypeType ns0:float ns1:formatType ns0:gDay ns0:gMonth ns0:gMonthDay ns0:gYear ns0:gYearMonth ns0:hexBinary ns0:int ns0:integer ns0:language ns1:latLonPairType ns1:listCityNamesType ns1:listLatLonType ns0:long ns0:negativeInteger ns0:nonNegativeInteger ns0:nonPositiveInteger ns0:normalizedString ns0:positiveInteger ns1:productType ns1:sectorType ns0:short ns0:string ns0:time ns0:token ns0:unsignedByte ns0:unsignedInt ns0:unsignedLong ns0:unsignedShort ns1:weatherParametersType ns1:zipCodeListType''' 

for match in re.findall(r"[a-zA-Z]+?\s*\([a-z]*?[0-9]*?:",text): 
    print match.split("(")[0] 
+0

@P2bM:谢谢。该解决方案适用于多个单元测试! – TheDodo 2011-04-06 04:38:31

+0

欢迎来到stackoverflow :) – P2bM 2011-04-06 15:45:57

0

你想要一个正则表达式来找到它们或每一个吗?你需要返回哪些数据(我假设()和对象名称的内容)?

从你有什么猜测,我认为这样的事情会工作:

((CornerPoints|LatLonListZipCode|other|names)\(.*\))) 

将匹配在上半场的一个名称,然后(data)组后(您可能要使它非贪婪)。

如果您使用更多信息编辑问题或评论,我会编辑答案。

+0

在这里解析泡沫的输出没有什么意义。有API的方法来做到这一点。至少打印到控制台的结果有一种可以通过Python迭代的数据结构。 – 2011-04-06 02:41:30

+0

我可以看到一个正则表达式是一个抓取一个对象的快速和肮脏的方法,但它肯定不是最好的。需要更多的信息,为什么TheDodo想要使用正则表达式和目标是什么,也许有一些愚蠢的要求? – ssube 2011-04-06 02:44:29

+0

他想要一个正则表达式,因为他不知道更好 – 2011-04-06 02:48:22

0

@peachykeen:是的,它需要是非贪婪的,否则。*会一直跑到最后'''字符串中。您还需要匹配组,最好命名为,以便引用您匹配的内容:

/(?P<key>name1|name2|...)(?P<value>\(.*?\))/ 
+0

@RestRisiko:我想要做的是:我有这个文件包含此文本(作为Suds客户端响应:))在txt文件中。现在我想要做的就是只提取由WebService提供的“方法”名称。稍后将这些所有方法名称都写入不同的文本文件。 – TheDodo 2011-04-06 04:33:23

相关问题