简体   繁体   English

收到错误未知主机:www.google.com

[英]getting error Unknow Host : www.google.com

i want to parse the webpage, iam using htmlunit, when iam running the code, iam getting below error.我想解析网页,我正在使用 htmlunit,当我运行代码时,我遇到了以下错误。

import java.net.URL;
import java.util.List;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class scrapImage {

      public static void main(String[] args) throws Exception      { 
          URL url = new URL("http://www.google.com");
          //WebClient webClient = new WebClient(Opera);     
          WebClient webClient = new WebClient();    
          HtmlPage currentPage = (HtmlPage) webClient.getPage(url);    
          //get list of all divs      
          final List<?> images = currentPage.getByXPath("//img");      
          for (Object imageObject : images) {           
              HtmlImage image = (HtmlImage) imageObject;            
              System.out.println(image.getSrcAttribute());       
              }         //webClient.closeAllWindows();           } } 
          }
      }

Error Message:错误信息:

Exception in thread "main" java.net.UnknownHostException: www.google.com
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:196)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
    at java.net.Socket.connect(Socket.java:530)
    at java.net.Socket.connect(Socket.java:480)
    at java.net.Socket.<init>(Socket.java:377)
    at java.net.Socket.<init>(Socket.java:251)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
    at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:97)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1430)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1388)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:325)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386)
    at htmlunit.scrapImage.main(scrapImage.java:16)

Can anyone let me know the solution for above exception.谁能告诉我上述异常的解决方案。

I think its problem with your.net connection or your firewall may block the java program to access inte.net.我认为您的 .net 连接问题或您的防火墙可能会阻止 java 程序访问 inte.net。

I think you are behind the proxy or firewall.我认为你在代理或防火墙后面。 Check your current firewall status in your system.Also, if it is related to proxy, you can modify the code like this.检查您系统中当前的防火墙状态。另外,如果它与代理有关,您可以像这样修改代码。

System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "your proxy host name" );
System.getProperties().put( "proxyPort", "85" );

May be this will help you.可能这会对你有所帮助。

Seems there is some trouble with the Inte.net connection or you are behind a proxy, Inte.net 连接似乎有问题,或者您使用了代理,

set the proxy settings (Host/Port/Username/Password) if this is the case.如果是这种情况,请设置代理设置(主机/端口/用户名/密码)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.net.UnknownHostException:无法解析主机“www.google.com” - java.net.UnknownHostException: Unable to resolve host “www.google.com” Android,UnknownHostException:www.google.com,在设备上而不是模拟器上 - Android, UnknownHostException: www.google.com, on device,not emulator 的java.net.UnknownHostException:www.google.com - java.net.UnknownHostException:www.google.com 命令find -number A www.google.com的正则表达式是什么? - What is the regular expression of the command find -number A www.google.com? Sahi脚本的等效Java代码:_openWindow(“ http://www.google.com”,“ defaultSahiPopup”,[360,640]); - Equivalent Java code of Sahi script: _openWindow(“http://www.google.com”,“defaultSahiPopup”,[360,640]); 我正在尝试在我的办公室中使用JAVA ping www.google.com,但不能ping相同 - I am trying to ping www.google.com using JAVA in my office but it is not pinging the same Matcher.group() 正在返回预期结果的一部分。例如,网址“www.google.com”,我的匹配器正在返回“www”。 - Matcher.group() is returning a part of expected result .For ex a url "www.google.com" , my matcher is returning "www." org.xeustechnologies.googleapi.spelling.SpellCheckException:java.io.FileNotFoundException:https://www.google.com/tbproxy/spell?lang=zh_CN&amp;hl=zh-CN - org.xeustechnologies.googleapi.spelling.SpellCheckException: java.io.FileNotFoundException: https://www.google.com/tbproxy/spell?lang=en&hl=en Android Studio 中的 WebView 无法正确显示网站(即 www.google.com 没有徽标、搜索栏和屏幕上方的所有内容) - WebView in Android Studio does not show sites properly (i.e. www.google.com is without logo, search bar and all the stuff on upper screen) 如何更正unknow主机异常错误 - How to correct the unknow host exception error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM