如何使用选择器获取href元素?
我正在使用它从该网站获取项目并返回到列表。
Document doc = null;
try {
doc = Jsoup.connect("http://www.gamespy.com/index/release.html").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get all td's that are a child of a row - each game has 4 of these
Elements games = doc.select("tr> td.indexList1, tr > td.indexList2");
// Iterator over those elements
ListIterator<Element> postIt = games.listIterator();
while (postIt.hasNext()) {
// ...It
while (postIt.hasNext()) {
// Add the game text to the ArrayList
String name = postIt.next().text();
String platform = postIt.next().text();
String genre = postIt.next().text();
String releaseDate = postIt.next().text();
gameList.add(new GameRelease(name, platform, genre, releaseDate));
Log.v(TAG, name +platform + genre +releaseDate);
}
这是每个项目的 html
<tr>
<td class="indexList1" align="left">
<a href="http://pc.gamespy.com/pc/hacker-evolution-duality-/" class="b1">
<em>Hacker Evolution Duality </em>
</a>
</td>
<td class="indexList1" align="center">
PC
</td>
<td class="indexList1" align="center">
Adventure
</td>
<td class="indexList1" align="center">
August 15, 2011
<!--08/15/2011-->
</td>
每个项目都有相同的模式,但我想知道我是否也可以检索每个项目的 url。你们可能还需要查看 html 的源代码才能获得更好的想法。
但我想将每个项目的 url 存储在字符串中。
I am using this to get items from this website and return to a list.
Document doc = null;
try {
doc = Jsoup.connect("http://www.gamespy.com/index/release.html").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get all td's that are a child of a row - each game has 4 of these
Elements games = doc.select("tr> td.indexList1, tr > td.indexList2");
// Iterator over those elements
ListIterator<Element> postIt = games.listIterator();
while (postIt.hasNext()) {
// ...It
while (postIt.hasNext()) {
// Add the game text to the ArrayList
String name = postIt.next().text();
String platform = postIt.next().text();
String genre = postIt.next().text();
String releaseDate = postIt.next().text();
gameList.add(new GameRelease(name, platform, genre, releaseDate));
Log.v(TAG, name +platform + genre +releaseDate);
}
This is the html for the each item
<tr>
<td class="indexList1" align="left">
<a href="http://pc.gamespy.com/pc/hacker-evolution-duality-/" class="b1">
<em>Hacker Evolution Duality </em>
</a>
</td>
<td class="indexList1" align="center">
PC
</td>
<td class="indexList1" align="center">
Adventure
</td>
<td class="indexList1" align="center">
August 15, 2011
<!--08/15/2011-->
</td>
Each item has the same pattern but i want to know could i retreive the url for each item too. You guys may need to view the source of the html too get a better idea.
But i want to store the url for each item in a string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:在你的情况下:
EDIT: In your case: