无法从特定网站的Jsoup连接获取HTML文档

时间:2018-11-10 16:30:09

标签: java html netbeans jsoup

当我尝试在连接到该特定网站后请求HTML文档时(当我将Jsoup用于其他网站时未发生此错误),我收到下一个错误。

代码:

LocalDateTime date = LocalDateTime.now();
Document doc = Jsoup.connect("https://www.twicenest.com/index.php?mid=schedule&pGanjioption=1&pYear=" + date.getYear() + "&pMonth=" + date.getMonthValue()).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36").get();

// do something with doc

错误:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
    at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
    at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:117)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at org.jsoup.internal.ConstrainableInputStream.read(ConstrainableInputStream.java:64)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at java.io.BufferedReader.fill(BufferedReader.java:161)
    at java.io.BufferedReader.read1(BufferedReader.java:212)
    at java.io.BufferedReader.read(BufferedReader.java:289)
    at java.io.Reader.read(Reader.java:140)
    at org.jsoup.parser.CharacterReader.bufferUp(CharacterReader.java:53)
    at org.jsoup.parser.CharacterReader.consume(CharacterReader.java:98)
    at org.jsoup.parser.TokeniserState$40.read(TokeniserState.java:803)
    at org.jsoup.parser.Tokeniser.read(Tokeniser.java:57)
    at org.jsoup.parser.TreeBuilder.runParser(TreeBuilder.java:51)
    at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:45)
    at org.jsoup.parser.Parser.parseInput(Parser.java:39)
    at org.jsoup.helper.DataUtil.parseInputStream(DataUtil.java:153)
    at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:851)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:296)
    at view.ONCEApp.start(ONCEApp.java:51)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    ... 1 more

我已经尝试使用Java工具(URL,URLConnection)中的版本从该网站上进行阅读,并通过使用这些工具成功地做到了这一点。但是它们没有提供与Jsoup相同的过滤方法。

0 个答案:

没有答案