Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jsoup-无法获取与浏览器中相同的HTML内容_Java_Jsoup - Fatal编程技术网

Java Jsoup-无法获取与浏览器中相同的HTML内容

Java Jsoup-无法获取与浏览器中相同的HTML内容,java,jsoup,Java,Jsoup,我正在尝试获取manta.com的html内容: 这是代码: private static final String BROWSER = " Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0"; private static final int TIMEOUT = 13_000; private static final String Accept_Value = "text/html,app

我正在尝试获取manta.com的html内容: 这是代码:

    private static final String BROWSER = " Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0";
private static final int TIMEOUT = 13_000;
private static final String Accept_Value = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
private static final String Accept_Encoding_Value = "gzip, deflate";


public static void main(String[] args) throws IOException {
    getRestPageUrlsInPage("http://www.manta.com/search?search=restaurants&pg=3&pt=34.0396,-118.2661&search_location=Los%20Angeles%20CA");

}

public static List<String> getRestPageUrlsInPage(String pageUrl) throws IOException {

    List<String> restPageUrlsInPage = new ArrayList<>();
    Response response = Jsoup.connect(pageUrl).userAgent(BROWSER)

            .execute();

    Document docOfPage = Jsoup.connect(pageUrl).ignoreContentType(true)
            .userAgent(BROWSER).timeout(TIMEOUT)
            .header("Accept", Accept_Value)
            .header("Accept-Encoding", Accept_Encoding_Value)
            .cookies(response.cookies())
            .get();

    Elements el = docOfPage.select("a.media-heading");

    for (Element element : el) {
        System.out.println(element);
    }

    return restPageUrlsInPage;

}
所以当我运行它时,它没有得到浏览器中该URL的内容-

我知道然后必须发送标题,但它不太起作用,或者我做错了什么。 那么我该如何解决这个问题呢


提前感谢。

您得到了什么而不是预期的结果?您确定没有通过AJAX加载内容吗?如果是这样的话,你在JSOUP上就不走运了,除非你知道如何点击ajax请求。我得到了这个:是的,通过ajax请求加载内容……我发现ajax url和传递url是一样的。只是尝试了一下,它从网站上打印了餐厅。。。您使用的是哪个JSOUP版本?