现在我在reddit上调用页面上的所有链接并将其打印出来,但是我可以添加到循环中以仅保留以http://www.reddit.com/r/askcience/开头的链接?
Document doc;
try {
doc = Jsoup.connect("http://www.reddit.com/r/askscience/search?q=flair%3A%27Psych%27&sort=top&restrict_sr=on").get();
Elements links = doc.select("a[href]");
for (Element link : links) {
System.out.println("\nlink : " + link.attr("href"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
是的,你得read the docs。
[attr^=valPrefix] elements with an attribute named "attr", and value starting with "valPrefix"
否则,你可以吮吸所有链接,并在字符串上使用正则表达式或startsWith()