示例:
<!-- Font Awesome -->
<link href="static/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Ionicons -->
<link href="static/ionicons/4.1.2/css/ionicons.min.css" rel="stylesheet">
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.nio.file.Files
import java.nio.file.Paths
import java.util.regex.Matcher
def file = new File(/C:\Users\kiss\IdeaProjects\demo.html/)
def collect = file.readLines()
.findAll { it.contains(/"static/) }
.collect {
println it
Matcher matcher = it =~ $/.*"static/(.+s)".*/$
matcher[0][1]
}
println collect
def httpClient = HttpClient.newBuilder().build()
collect.each {
def request = HttpRequest.newBuilder(URI.create("http://cdn.staticfile.org/$it")).GET().build()
def response = httpClient.send(request, HttpResponse.BodyHandlers.ofString())
println response.body()
Files.writeString(Paths.get("d:/stt/$it").createParentDirectories(), response.body())
}
标签:Groovy,Http,java,http,collect,正则,file,import,def
From: https://www.cnblogs.com/windyWu/p/17173114.html