【问题标题】:How to access the web page contents如何访问网页内容
【发布时间】:2015-04-11 15:06:28
【问题描述】:

我将网页的文本存储在字符串中。但是网页的某些内容没有存储在字符串中。我不知道为什么不存储类似 div 的元素中的内容。即使是 div 内的链接也无法使用我实现的网络爬虫访问。谁能帮我解决这个问题!!!。

 List<String> tags = new ArrayList<String>();
for(int i=0;i<8;i++)
{
Document doc = Jsoup.connect("some link here").get();
Elements taglinks = doc.select("html");
for (Element link : taglinks) {
tags.add(link.text());}
System.out.println(tags);

【问题讨论】:

  • 你能分享一些你到目前为止尝试过的代码吗?
  • 请编辑您的答案,而不是在 cmets 中添加您的代码
  • 它适用于某些链接,但不适用于所有链接

标签: java html web web-crawler jsoup


【解决方案1】:

您的问题不够清楚,但从您的代码中,我了解到您正在寻找,保存链接的文本并使用您必须使用的 .select() 语法 doc.select("a[href"]); 然后你可以使用你当前的 for 循环。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 2015-05-22
    • 1970-01-01
    • 2012-11-18
    相关资源
    最近更新 更多