简体   繁体   English

使用Jsoup库从android网站上获取html表数据,

[英]Get data of html table from a website in android using Jsoup library,

I am working on an app where I am parsing some data from one or two websites. 我正在开发一个应用程序,其中要解析一个或两个网站的一些数据。 Luckily I did it for some of my targeted data but not. 幸运的是,我为某些目标数据执行了此操作,但没有。 Now that I am using Jsoup for parsing the data from a website I used same jsoup format to get data of phase 2 as I did for phase 1 of my app but this time nothing is fetching arraylist showing up blank. 现在,我正在使用Jsoup来解析来自网站的数据,我使用与应用程序第1阶段相同的jsoup格式来获取第2阶段的数据,但是这次没有任何操作可获取显示空白的arraylist。 I checked both HTML codes and there is a bit of difference in both. 我检查了两个HTML代码,两者都有一些区别。

In my phase1 i parsed the table using it's class and then i get the respective of that table. 在我的phase1中,我使用表的类来解析表,然后获取该表的相应内容。 In the 2nd phase, the format of table and its tr & tds are different so i am struggling to figure it out. 在第二阶段中,表格的格式及其tr&tds是不同的,因此我正在努力解决。 I am posting the html code from which i want to get data. 我正在发布要从中获取数据的html代码。

 <div class="view-content"> <table class="views-table cols-3"> <thead> </thead> <tbody> <tr class="odd views-row-first views-row-last"> <td class="views-field views-field-counter"> 1 </td> <td class="views-field views-field-body"> <p>some text here</p> </td> <td class="views-field views-field-field-notif-pdf"> <a href="https://someurl.pdf" target="_blank"></a> Size :- 1.85 MB, Language:- English</td> </tr> </tbody> </table> </div> 

I want the data inside above table tag and i am having problems to figure it out how it will be done with all classes in tr and td. 我想要上面table标记中的数据,并且在弄清楚如何对tr和td中的所有类进行处理时遇到问题。 Any help or suggestion will be highly appreciated.. 任何帮助或建议将不胜感激。

THANK YOU! 谢谢!

You can use selectors in Jsoup: 您可以在Jsoup中使用选择器:

 File input = new File("path_to_html/test.html");
        Document doc = Jsoup.parse(input, StandardCharsets.UTF_8.name());
///select table body
        Element tbody = doc.select("tbody").first();

other examples at: 其他示例在:

https://jsoup.org/cookbook/extracting-data/selector-syntax https://jsoup.org/cookbook/extracting-data/selector-syntax

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM