如何使用java从html页面获取数据?
如何从XML/HTML页面获取数据 我想制作一个安卓应用程序,在这个应用程序中,用户会收到一个关于学校课程发生问题的通知。 这是网站的外观: 安装应用程序后,用户填写他们的学校班级(klas)。 我想从表中选择数据,如果是他们的类,用户应该收到通知。(例如:如何使用java从html页面获取数据?,java,android,html,xml,xml-parsing,Java,Android,Html,Xml,Xml Parsing,如何从XML/HTML页面获取数据 我想制作一个安卓应用程序,在这个应用程序中,用户会收到一个关于学校课程发生问题的通知。 这是网站的外观: 安装应用程序后,用户填写他们的学校班级(klas)。 我想从表中选择数据,如果是他们的类,用户应该收到通知。(例如: if ( userClass == klas ), then alert ("hey, " + was + " will be " + was + "because of" + opmerking); 诸如此类。但我不知道如何从表中挑
if ( userClass == klas ), then alert ("hey, " + was + " will be " + was + "because of" + opmerking);
诸如此类。但我不知道如何从表中挑选数据,这是一个奇怪的页面。这使得它变得更加困难,因为页面从(1/2)逐渐变为(2/2)(每页最多10个列表,因此50个列表=5页),请在此处查找示例:。
我应该如何挑选数据并将它们放入java变量中
我需要从代码中挑选一些东西
<tr class='list odd'>
<td class="list" align="center">6V</td>
<td class="list" align="center">5</td>
<td class="list" align="center">fatl1</td>
<td class="list" align="center">fatl1</td>
<td class="list" align="center">MPs</td>
<td class="list" align="center">MPs</td>
<td class="list" align="center">D03</td>
<td class="list" align="center">lokaal wissel</td>
6V
5.
fatl1
fatl1
议员
议员
D03
洛卡尔·维塞尔
网站完整代码:
<html>
<head>
<title>Roosterwijzigingen Locatie Rijnwoude</title>
<meta http-equiv="expires" content="0">
<style type="text/css">
<!--
/* page title */
div.mon_title
{
font-weight: bold;
font-size: larger;
}
table.info
{
background-color: #FFB515;
border: 2px;
border-style:solid;
}
table.mon_list
{
background-color: #FFB515;
border: 2px;
border-style:solid;
}
td.info
{
font-size: 15px;
font-style: normal;
font-weight: 100;
}
th.list,
td.list
{
background-color: #FFB515;
font-size: 19pt;
font-style: normal;
font-weight: 100;
border: 2px;
border-style:solid;
}
-->
</style>
<meta name="generator" content="Untis 2013">
<meta name="company" content="Gruber & Petters Software, A-2000 Stockerau, Austria, www.grupet.at">
</head>
<body bgcolor="#FEE9B1">
<CENTER>
<TABLE align="bottom" cellspacing="3" cellpadding="2">
<TR>
<TD align="bottom">
<font face="Verdana" size="6" color="#911083">Roosterwijzigingen</font>
<br><font size="4" color="#000000" face="Arial">Vestiging Rijnwoude</font>
</TD>
<TD> </TD>
<TD>
<TABLE width="100%" cellspacing="2" cellpadding="2">
<tr>
<TD></TD>
<TD> </TD>
<TD></TD>
<TD> </TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD> </TD>
<TD></TD>
<TD> </TD>
<TD><font size="-2">Gewijzigd 16-5-2013 13:54</size></TD>
</TR>
</TABLE>
</TD>
</tr>
</TABLE>
<p>
<font size="4" face="Arial">
<div class="mon_title">18-05-2013 Maandag</div>
<table class="mon_list" >
<tr class='list'>
<th class="list" align="center">Klas</th>
<th class="list" align="center">uur</th>
<th class="list" align="center">was</th>
<th class="list" align="center">wordt</th>
<th class="list" align="center">was</th>
<th class="list" align="center">wordt</th>
<th class="list" align="center">Vaklokaal</th>
<th class="list" align="center">opmerking</th>
</tr>
<tr class='list odd'>
<td class="list" align="center" style="background-color: #6f95d5">4H</td>
<td class="list" align="center" style="background-color: #6f95d5">5-6</td>
<td class="list" align="center" style="background-color: #6f95d5">nat1</td>
<td class="list" align="center" style="background-color: #6f95d5">---</td>
<td class="list" align="center" style="background-color: #6f95d5">MEn</td>
<td class="list" align="center" style="background-color: #6f95d5">---</td>
<td class="list" align="center" style="background-color: #6f95d5">---</td>
<td class="list" align="center" style="background-color: #6f95d5">aulauur</td>
</tr>
<tr class='list even'>
<td class="list" align="center">4V</td>
<td class="list" align="center">1</td>
<td class="list" align="center">econ3</td>
<td class="list" align="center">econ3</td>
<td class="list" align="center">SVn</td></td>
<td class="list" align="center">SVn</td>
<td class="list" align="center">310</td>
<td class="list" align="center">lokaal wissel</td>
</tr>
<tr class='list odd'>
<td class="list" align="center">6V</td>
<td class="list" align="center">5</td>
<td class="list" align="center">fatl1</td>
<td class="list" align="center">fatl1</td>
<td class="list" align="center">MPs</td>
<td class="list" align="center">MPs</td>
<td class="list" align="center">D03</td>
<td class="list" align="center">lokaal wissel</td>
</tr>
<tr class='list even'>
<td class="list" align="center" style="background-color: #6f95d5">6V</td>
<td class="list" align="center" style="background-color: #6f95d5">8</td>
<td class="list" align="center" style="background-color: #6f95d5">gs</td>
<td class="list" align="center" style="background-color: #6f95d5">---</td>
<td class="list" align="center" style="background-color: #6f95d5">NBa</td>
<td class="list" align="center" style="background-color: #6f95d5">---</td>
<td class="list" align="center" style="background-color: #6f95d5">---</td>
<td class="list" align="center" style="background-color: #6f95d5">aulauur</td>
</tr>
<tr class='list odd'>
<td class="list" align="center">6V</td>
<td class="list" align="center">7</td>
<td class="list" align="center">nat7</td>
<td class="list" align="center">nat7</td>
<td class="list" align="center">MEn</td>
<td class="list" align="center">JHo</td>
<td class="list" align="center">001</td>
<td class="list" align="center">het 6e of 8e uur</td>
</tr>
</table>
<p>
<font size="3" face="Arial">
Groene Hart Rijnwoude
</font></font>
</CENTER>
<p><center><font face="Arial" size="2"><a href="http://www.grupet.at" target="_blank" >Untis roostersoftware</a></font></center>
</body>
</html>
Roosterwijzigingen Rijnoude酒店
雄鸡
利恩沃德遗迹酒店
Gewijzigd 16-5-2013 13:54
2013年5月18日马恩达格
克拉斯
uur
是
沃特
是
沃特
瓦克洛卡尔
奥默金
4H
5-6
nat1
---
男人
---
---
奥劳尔
4V
1.
经济3
经济3
SVn
SVn
310
洛卡尔·维塞尔
6V
5.
fatl1
fatl1
议员
议员
D03
洛卡尔·维塞尔
6V
8.
gs
---
美国篮球职业联盟
---
---
奥劳尔
6V
7.
nat7
nat7
男人
JHo
001
het 6e/8e uur
格罗尼·哈特·里霍德
仅在格式良好的HTML文档上使用XML解析器。用于解析HTML文档,如您发布的文档(似乎格式不正确),建议使用。阅读烹饪书介绍,几分钟后你就可以开始了。页面输出是HTML格式的。因此,我更喜欢使用。它标准、简单,并且贯穿你给出的每一段HTML
在你的android项目中包括JSOUP库。它们的大小相对适中,值得付出努力,因为你的应用程序似乎要阅读大量html
public static void main(String[] args) throws Exception {
// Get The Site and Parse it
Document doc = Jsoup.connect("http://suse.ghlyceum.nl/dagrooster/lwoo/").get();
// Select Table
Element table = document.select(".mon_list").first();
Iterator<Element> lines = table.select("tr").iterator();
while (lines.hasNext()) {
Element line = lines.next();
System.out.println("TD text : "+line.text());
}
}
publicstaticvoidmain(字符串[]args)引发异常{
//获取站点并解析它
Document doc=Jsoup.connect(“http://suse.ghlyceum.nl/dagrooster/lwoo/).get();
//选择表
元素表=文档。选择(“.mon_列表”).first();
迭代器行=table.select(“tr”).Iterator();
while(lines.hasNext()){
元素行=行。下一步();
System.out.println(“TD text:+line.text());
}
}
这只是java代码。因此,您可以将其与现有的Android代码结合使用来填充列表元素(而不是像代码中所示输出到控制台),并在视图中显示
URL url = new URL("http://facebook.com");
in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
}
应该足够让您开始了。您可以使用javascript获取广泛的数据。在您的示例表中,使用类“mon_list”。然后您可以使用xml解析来获取特定的数据并将它们存储在java变量中。