简体   繁体   English

Jsoup不会提取文本

[英]Jsoup Wont Extract Text

I cannot extract the text from the css path what am i doing wrong? 我无法从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());

    }
}

The output should be EXAMPLE 输出应为EXAMPLE

Thanks. 谢谢。

This can get you the source code properly. 这样可以正确获取源代码。

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

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

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

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