Class WebClient不存在

问题描述 投票:0回答:1
import com.gargoylesoftware.htmlunit.WebClient;

public class Main {
    public static void main(String[] args) throws Exception  {
        WebClient webClient = new WebClient();
        HtmlPage page = webClient.getPage("http://www.google.com");
    }
}

但是我收到以下错误:

Error:(6, 9) java: cannot find symbol
 symbol:   class WebClient
 location: class Main

我试图在网上搜索错误。我得到404。

java intellij-idea
1个回答
0
投票

上面提到的代码对我有用

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

import java.io.IOException;


public class Demo {

    public static void main(String[] args) throws IOException {

        WebClient webClient = new WebClient();
        HtmlPage page = webClient.getPage("http://www.google.com");
        System.out.println(page.asText());
    }
}

等级依赖

  compile group: 'net.sourceforge.htmlunit', name: 'com.springsource.com.gargoylesoftware.htmlunit', version: '2.6.0'

© www.soinside.com 2019 - 2024. All rights reserved.