关于webmagic爬取Https网站报错的解决办法

发布时间:2019-11-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了关于webmagic爬取Https网站报错的解决办法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
目前webmagic最新版是0.7.3版本,在爬取只支持TLS1.2https站点会报错
javax.net.ssl.SSLException: Received fatal alert: PRotocol_version     at sun.securITy.ssl.Alerts.getSSLException(Alerts.java:208)     at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)     at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)     at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)     at sun.security.ssl.SSLSocketImpl.PErformInitialHandshake(SSLSocketImpl.java:1375)     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)     at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)     at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)     at org.apache.http.impl.conn.DefaultHttpClientConnectionoperator.connect(DefaultHttpClientConnectionOperator.java:141)     at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)     at org.apache.http.impl.execchain.MainClientExec.establishroute(MainClientExec.java:380)     at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)     at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)     at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)     at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)     at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)     at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)     at us.codecraft.webmagic.downloader.HttpClientDownloader.download(HttpClientDownloader.java:85)

目前作者说会在0.7.4版本发布修复错误,目前的解决办法是:

临时适配方式,修改HttpClientGenerator中的buildSSLConnectionSocketFactory方法,

return new SSLConnectionSocketFactory(createIgnoreverifySSL(), new String[]{"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"},                     null,                     new DefaultHostnameVerifier())

重写自己实现的HttpClientDownloader,并设置到Spider中。

作者原文:Https下无法抓取只支持TLS1.2的站点

我已经把码重新编译打包了,如果自己懒得编译可以用我打包好的这个:webmagic-core-0.7.3.jar

脚本宝典总结

以上是脚本宝典为你收集整理的关于webmagic爬取Https网站报错的解决办法全部内容,希望文章能够帮你解决关于webmagic爬取Https网站报错的解决办法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。