2010-06-03 1 views
0

여기 읽고있다 : http://groovy.codehaus.org/modules/http-builder/doc/get.htmlHTTP 작성기/Groovy - 원본 텍스트 및 XmlSlurper 출력을 가져 오시겠습니까?

내가 얻을 수있을 것

내가)를 사용 NekoHTML에 의해 구문 분석으로 XMLSlurper 출력 : 사용

def http = new HTTPBuilder('http://www.google.com') 
def html = http.get(path : '/search', query : [q:'Groovy']) 

II) 원시 텍스트 :

http.get(path : '/search', 
      contentType : TEXT, 
      query : [q:'Groovy']) { resp, reader ->   
    println "response status: ${resp.statusLine}" 
    println 'Headers: -----------' 
    resp.headers.each { h -> 
    println " ${h.name} : ${h.value}" 
    } 
    println 'Response data: -----' 
    System.out << reader 
    println '\n--------------------' 
} 

몇 가지 문제가있어서 받고 싶습니다. 둘 다 (i) 및 (ii)는 실제 HTML에서 XmlSlurper 코드를 디버깅합니다.

제안 방법에 대해 어떻게 생각하나요?

parseString (string) 메서드 나 parse (reader) 메서드를 사용하여 관련 문자열로 XmlSlurper 개체를 쉽게 인스턴스화 할 수 있지만 Neko 처리 단계가 올바르지 않은 것 같습니다.

힌트가 있습니까?

감사합니다. 미샤

답변

3

여기에 있습니다. http://groovy.codehaus.org/Testing+Web+Applications

def html=http.get(uri:'http://www.google.com',contentType:groovyx.net.http.ContentType.TEXT) { resp,reader -> 
    def s=reader.text 
    new File("temp.html")<<s 
    new XmlSlurper(new org.cyberneko.html.parsers.SAXParser()).parseText(s)   
} 

감사합니다 :

은 알아 냈어! Misha

+1

감사합니다. – MeIr