[英]Jsoup Wont Extract Text
我無法從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
謝謝。
這樣可以正確獲取源代碼。
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.