Questions tagged «jsoup»

15
使用jsoup将html转换为纯文本时,如何保留换行符?
我有以下代码: public class NewClass { public String noTags(String str){ return Jsoup.parse(str).text(); } public static void main(String args[]) { String strings="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN \">" + "<HTML> <HEAD> <TITLE></TITLE> <style>body{ font-size: 12px;font-family: verdana, arial, helvetica, sans-serif;}</style> </HEAD> <BODY><p><b>hello world</b></p><p><br><b>yo</b> <a href=\"http://google.com\">googlez</a></p></BODY> </HTML> "; NewClass text = new NewClass(); …
101 java  jsoup 

6
我在Jsoup中收到SocketTimeoutException:读取超时
当我尝试使用Jsoup解析许多HTML文档时,出现SocketTimeoutException。例如,我得到了一个链接列表: <a href="www.domain.com/url1.html">link1</a> <a href="www.domain.com/url2.html">link2</a> <a href="www.domain.com/url3.html">link3</a> <a href="www.domain.com/url4.html">link4</a> 对于每个链接,我都会解析链接到URL的文档(来自href属性),以获取这些页面中的其他信息。因此,我可以想象这需要花费很多时间,但是如何关闭此异常呢? 这是整个堆栈跟踪: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at java.io.BufferedInputStream.fill(Unknown Source) at java.io.BufferedInputStream.read1(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source) at sun.net.www.http.HttpClient.parseHTTP(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at java.net.HttpURLConnection.getResponseCode(Unknown Source) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:381) at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:364) at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:143) at org.jsoup.helper.HttpConnection.get(HttpConnection.java:132) …
100 java  jsoup 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.