繁体   English   中英

java.net.MalformedURLException:未知协议:地图

[英]java.net.MalformedURLException: unknown protocol: maps

我在 Selenium Webdriver (Java) 中遇到异常

java.net.MalformedURLException:未知协议:地图

在检查页面上存在的所有活动链接(URL)时

代码如下:

for(int j=0;j<activeLinks.size();j++)
{
    String strURL = activeLinks.get(j).getAttribute("href");
    HttpURLConnection connection =  (HttpURLConnection)newURL(activeLinks.get(j).getAttribute("href")).openConnection();
    connection.connect();
    String response = connection.getResponseMessage(); //ok
    connection.disconnect();
    System.out.println(activeLinks.get(j).getAttribute("href")+"--> " +response);
}

我建议您检查每个 href 是否存在 http/https 协议,如果没有则添加它。

前任:

activeLinks.forEach(link -> {
    String strURL = link.getAttribute("href");
    strUrl = strUrl.startsWith("http") ? strUrl : "https://".concat(strUrl);
    HttpURLConnection connection =  (HttpURLConnection) new URL(strUrl).openConnection();
    connection.connect();
    String response = connection.getResponseMessage(); //ok
    connection.disconnect();
    System.out.println(String.format("%s --> %S", strUrl,response));
})

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM