我试图查看 html 页面中是否存在特定字符串,但我似乎找不到一种简单的方法来获取代表正文的字符串。
我尝试过:
http.request(Method.GET, { req ->
uri.path = '/x/app/main'
response.success = { resp, reader ->
assert resp.status == 200
println reader.text.startsWith('denied')
}
response.failure = { resp ->
fail("Failure reported: ${resp.statusLine}")
}
})
但是 reader.text 是一个 NodeChildren 对象。
如何获取字符串形式的 html(或更具体地说,正文的上下文)?
最佳答案
您可以直接从响应中获取输入流。试试这个:
http.request(Method.GET, { req ->
uri.path = '/x/app/main'
response.success = { resp ->
assert resp.status == 200
println resp.entity.content.text.startsWith('denied')
}
response.failure = { resp ->
fail("Failure reported: ${resp.statusLine}")
}
})
关于html - 从groovy中的响应中获取html正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8729159/