JSoup:如何解析特定的链接 [英] JSoup:How to parse a specific link

查看:111
本文介绍了JSoup:如何解析特定的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个android应用程序,我试图只从下面的网站获取特定的链接,但我不能,因为该网站对所有类使用相同的名称(这只是网站HTML中的一小部分代码)。

I'm building an android app and I 'm trying to get only a specific link,from the following site but I cannot, because the site uses the same name for all classes (this only a small part from the site's HTML code).

<td class="td-file"><span class="td-value"  
id="JOT_FILECAB_label_wuid:gx:4c83ae813389c090" aria-hidden="true">
Ε.ΛΣΧ.ΑΕΝ.02 ΑΠΟ 22-2-2016.pdf</span><br />
<SPAN style="word-spacing: 3px;">
<a href="https://docs.google.com/viewer?a=v&amp;pid=sites&amp;srcid=ZGVmYXVsdGRvbWFpbnxhZW5tYWttZWNofGd4OjRjODNhZTgxMzM4OWMwOTA" dir="ltr" target="_blank">Προβολή</a> 
<a href="/site/aenmakmech/tmemata/%CE%95.%CE%9B%CE%A3%CE%A7.%CE%91%CE%95%CE%9D.02%20%CE%91%CE%A0%CE%9F%2022-2-2016.pdf?attredirects=0&amp;d=1" dir="ltr">Λήψη</a>
</SPAN></td>

如何解析使用id =JOT_FILECAB_label_wuid:gx:4c83ae813389c090?

How to parse using id="JOT_FILECAB_label_wuid:gx:4c83ae813389c090"?

推荐答案

我找到了一个简单的解决方案,它解决了我的问题。我从网站中选择所有href,我将这些元素存储在一个数组中,然后从数组中选择我想要的。

I found a simple solution, which solves my problem. I select all the "href" from the site, I store the elements in an array, and from array I choose the one I want.

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) {
  Document doc = null;

  try {
   doc = Jsoup.connect("https://sites.google.com/site/aenmakmech/tmemata").get();
   Elements links = doc.select("a[href]");

   String[] urls = new String[links.size()];
   for (int i = 0; i < links.size(); i++) {
    urls[i] = links.get(i).attr("href");
    //System.out.println(prices[i]);
   }

   String specific_url = urls[77];
   System.out.print(specific_url);

  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }


 }
};

感谢您的帮助。

这篇关于JSoup:如何解析特定的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆