如何在https站点中查找断开的链接并使用代理

时间:2018-06-20 12:21:53

标签: java selenium

下面是我的代码。我的应用程序网址适用于HTTPS和代理。这段代码有什么问题?

对于所有网址,我都会显示错误。

public void brokenLink() throws IOException {
        List<WebElement> urllinks = driver.findElements(By.tagName("a"));
        for (int i = 0; i < urllinks.size(); i++) {
            WebElement urllink = urllinks.get(i);
            String link = urllink.getAttribute("href");         
            verifylinkActive(link);
        }
    }

    private void verifylinkActive(String link) throws IOException {
        try {
            System.out.println(link);
            // TODO Auto-generated method stub
            URL activelinks = new URL(link);
            System.setProperty("https.proxyHost", "proxy.abc.com");
            System.setProperty("https.proxyPort", "8080");
            HttpURLConnection httpUrlConnect = (HttpURLConnection) activelinks.openConnection();

            httpUrlConnect.usingProxy();
            httpUrlConnect.setConnectTimeout(3000);
            httpUrlConnect.connect();
            System.out.println(httpUrlConnect.getResponseCode());
            if (httpUrlConnect.getResponseCode() == 200) {
                System.out.println(link + "-" + httpUrlConnect.getResponseMessage());
            }
            if (httpUrlConnect.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
                System.out.println(
                        link + "-" + httpUrlConnect.getResponseMessage() + "-" + HttpURLConnection.HTTP_NOT_FOUND);
            }
        } catch (Exception e) {
            System.out.println("Error");
        }
    }

0 个答案:

没有答案