我只想得到:
http://tamilblog.ishafoundation.org/nalvazhvu/vazhkai/
而不是所有这些:
<a href="http://tamilblog.ishafoundation.org/nalvazhvu/vazhkai/"></a>
我只是想把它应用到我的循环(部分):
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 NewClassssssss {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://tamilblog.ishafoundation.org/page/3//").get();
Elements section = doc.select("section#content");
Elements article = section.select("article");
Elements links = doc.select("a[href]");
for (Element a : section) {
// System.out.println("Title : \n" + a.select("a").text());
System.out.println(a.select("a[href]"));
}
System.out.println(links);
}
}
答案 0 :(得分:1)
代码中存在一些问题:
Elements links = doc.select("a[href]");
以上行从整个文档中获取所有链接,而不是仅包含文章。
for (Element a : section) {
// ...
}
上面的for循环适用于部分而不是链接。
select
方法Elements section = doc.select("section#content");
Elements article = section.select("article");
Elements links = doc.select("a[href]");
没有必要为层次结构中的每个节点执行选择。 Jsoup可以为您导航。这三行可以用一行代替:
Elements links = doc.select("section#content article a");
示例代码
以下是恢复所有三个先例点的示例代码:
Document doc = Jsoup.connect("http://tamilblog.ishafoundation.org/nalvazhvu/vazhkai/").get();
for (Element a : doc.select("section#content article a")) {
System.out.println("Title : \n" + a.text());
System.out.println(a.absUrl("href")); // absUrl is used here for *always* having absolute urls.
}
<强>输出强> 标题:
http://tamilblog.ishafoundation.org/kalyana-parisaga-isha-kaattupoo/
Title :
இதயம் பேசுகிறது
http://tamilblog.ishafoundation.org/isha-pakkam/idhyam-pesugiradhu/
Title :
வாழ்க்கை
http://tamilblog.ishafoundation.org/nalvazhvu/vazhkai/
Title :
கல்யாணப் பரிசாக ஈஷா காட்டுப்பூ…
http://tamilblog.ishafoundation.org/kalyana-parisaga-isha-kaattupoo/
... (truncated for brievety)
答案 1 :(得分:0)
{
"invocationId": "invocationIdExample",
"deliveryStreamArn": "arn:aws:kinesis:EXAMPLE",
"region": "us-west-2",
"records": [
{
"recordId": "49546986683135544286507457936321625675700192471156785154",
"approximateArrivalTimestamp": 1495072949453,
"data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4="
}
]
}