pom.xml
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class MyTest {
public static void main(String[] args) {
Document doc=getURLContent("https://www.gd.gov.cn/","UTF-8");
Elements elementsByClass = doc.select("li a");
Map<String,String> map=new HashMap<>();
List<String> titleList=new ArrayList<>();
for( Element element : elementsByClass){
String title=element.select("a").attr("title");
String href="https://www.gdzwfw.gov.cn"+element.select("a").attr("href");
if(StringUtils.isNotBlank(title)) {
map.put(title, href);
titleList.add(title);
}
}
System.out.println(map);
}
public static Document getURLContent(String url, String encoding) {
StringBuffer content = new StringBuffer();
try {
URL u = new URL(url);
InputStream in = new BufferedInputStream(u.openStream());
InputStreamReader theHTML = new InputStreamReader(in, encoding);
int c;
while ((c = theHTML.read()) != -1) {
content.append((char) c);
}
}
catch (MalformedURLException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
}
return Jsoup.parse(content.toString());
}
public void and()throws Exception {
try {
BufferedInputStream input1 = new BufferedInputStream(new FileInputStream(new File("D:\\2.mp3")));
BufferedInputStream input2 = new BufferedInputStream(new FileInputStream(new File("D:\\2.mp3")));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File("D:\\3.mp3")));
byte[] byt = new byte[1024];
int len;
while ((len = input1.read(byt)) != -1) {
out.write(byt, 0, byt.length);
out.flush();
}
while ((len = input2.read(byt)) != -1) {
out.write(byt, 0, byt.length);
out.flush();
}
input1.close();
input2.close();
out.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}