我想用jsoup解析一个网站,它成功地得到了我想要的细节,但我仍然得到很多例外而不是捕获
public static void main(String[] argv)
{
getGoogle();
}
private static void getGoogle() {
String url = "http://google.com";
Document doc = null;
try {
doc = Jsoup.connect(url).get();
Element body = doc.body();
}catch (Exception e) {
System.out.println("------------google------------");
System.out.println("getGoogle:" + e.getMessage());
}
}
当我使用调试模式时发现这是因为doc = Jsoup.connect(url).get();
这行,但是在我搜索了很多信息之后看起来还不错,下面是我得到的例外情况
Could not instrument class com/sun/deploy/security/MozillaJSSProvider: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:550)
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1099)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:562)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:608)
at java.base/java.lang.Class.forName(Class.java:448)
at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:847)
at java.base/java.util.ServiceLoader.access$600(ServiceLoader.java:390)
at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1071)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1294)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1379)
at java.base/sun.security.jca.ProviderConfig$ProviderLoader.load(ProviderConfig.java:334)
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:244)
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:238)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.security.jca.ProviderConfig.doLoadProvider(ProviderConfig.java:238)
at java.base/sun.security.jca.ProviderConfig.getProvider(ProviderConfig.java:218)
at java.base/sun.security.jca.ProviderList.getProvider(ProviderList.java:266)
at java.base/sun.security.jca.ProviderList.getIndex(ProviderList.java:296)
at java.base/sun.security.jca.ProviderList.getProviderConfig(ProviderList.java:280)
at java.base/sun.security.jca.ProviderList.getProvider(ProviderList.java:286)
at java.base/java.security.Security.getProvider(Security.java:470)
at java.base/sun.security.ssl.SignatureAndHashAlgorithm.<clinit>(SignatureAndHashAlgorithm.java:415)
at java.base/sun.security.ssl.SSLSessionImpl.<init>(SSLSessionImpl.java:182)
at java.base/sun.security.ssl.SSLSessionImpl.<init>(SSLSessionImpl.java:150)
at java.base/sun.security.ssl.SSLSessionImpl.<clinit>(SSLSessionImpl.java:79)
at java.base/sun.security.ssl.SSLSocketImpl.init(SSLSocketImpl.java:596)
at java.base/sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:534)
at java.base/sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:72)
at java.base/sun.net.www.protocol.https.HttpsClient.createSocket(HttpsClient.java:413)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:162)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:163)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:651)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:676)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:676)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:628)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:260)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:249)
at test3.test3.getGoogle(test3.java:23)
at test3.test3.main(test3.java:12)
Could not instrument class com/sun/deploy/security/MozillaJSSProvider$ProviderService: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class com/sun/deploy/security/MozillaJSSProvider$ProviderService: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class sun/security/pkcs11/SunPKCS11: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class sun/security/pkcs11/wrapper/PKCS11Exception: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class sun/security/pkcs11/SunPKCS11$Descriptor: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
Could not instrument class com/sun/security/sasl/gsskerb/JdkSASL: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
Could not instrument class com/sun/security/sasl/gsskerb/JdkSASL$1: java.lang.IllegalArgumentException
at org.eclipse.jdt.launching.internal.org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jdt.launching.internal.weaving.ClassfileTransformer.transform(ClassfileTransformer.java:25)
at org.eclipse.jdt.launching.internal.javaagent.Premain$1.transform(Premain.java:51)
还有更多的例外.....并且所有人都没有抓住尝试......捕获
这是一个日食错误,你可以找到讨论here此外,这已经在SO中提出,this(https://stackoverflow.com/a/47109099/6039974)答案可能会帮助你。