jar包
commons-codec-1.11.jar
commons-logging-1.2.jar
fluent-hc-4.5.9.jar
httpclient-4.5.9.jar
httpclient-cache-4.5.9.jar
httpclient-osgi-4.5.9.jar
httpclient-win-4.5.9.jar
httpcore-4.4.11.jar
httpmime-4.5.9.jar
jna-4.5.2.jar
jna-platform-4.5.2.jar
jsoup-1.12.1.jar
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL;
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements;
public class PaText {
public static void main(String[] args) { String url1="#"; InputStream is=null; BufferedReader br=null; StringBuffer html=new StringBuffer(); String temp=""; try { URL url2 = new URL(url1); is = url2.openStream(); br= new BufferedReader(new InputStreamReader(is)); while ((temp = br.readLine()) != null) { html.append(temp); } if(is!=null) { is.close(); is=null; } Document doc = Jsoup.parse(html.toString()); Elements elements = doc.getElementsByTag("pre"); String res = elements.get(0).html(); String[] split = res.split(","); StringBuilder stringBuilder = new StringBuilder(); for (String string : split) { stringBuilder.append(","+string.trim()); } System.out.println(stringBuilder.toString());
} catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
}
|