Jsoup Wont提取文本

时间:2015-04-14 02:16:27

标签: java jsoup elements

我无法从css路径中提取文本我做错了什么?

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Main{

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

    Document doc;

    // need http protocol
    doc = Jsoup.connect("https://www.google.com.au/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=example").get();
    Elements links = doc.select("#uid_0 > div._OKe > ol > li:nth-child(2) > div > div.kno-ecr-pt.kno-fb-ctx");
    System.out.println("text : " + links.text());

    }
}

输出应为EXAMPLE

感谢。

1 个答案:

答案 0 :(得分:0)

这可以正确地为您提供源代码。

Document doc = Jsoup
.connect("your url")
.userAgent("Mozilla")
.timeout(5000)
.get();

Elements links = doc.select("your css path");