如果我想使用Java从网页中获取数据,我该从哪里开始呢?

发布于 2024-10-09 13:58:19 字数 328 浏览 0 评论 0原文

自从 Google 开始提供非常好的 电影院列表 布局,我想制作一个 Android 应用程序,用户可以从此页面获取信息并将其显示在他们输入的区域。

我不是问如何制作应用程序,而是问使用 Java 如何动态地从此网页获取信息?我可以将其解析为 XML 吗?这种方式似乎有点棘手。

Since Google started giving a very nice cinema listings layout, I would like to make an android app that the user could take the information from this page and display it for the area they input.

I'm not asking how to make the app, but using Java how would I go about dynamically taking the information from this webpage? Could I parse it as XML? It seems a little tricky this way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扛刀软妹 2024-10-16 13:58:19

从字面上看你对“标题”的疑问,请参阅我对此问题的回答,了解如何使用网络网址获取原始 html...
Android 开发人员:如何从网络中提取数据并在我的应用程序中使用这些数据?

我这样做并使用名为 HtmlCleaner 的第 3 方类,该类返回可使用 XPATH 搜索的 XML 。

然而,正如已经说过的,很可能有更好的方法来做你想做的事,尤其是来自 CommonsWare 的评论太真实了。这是很痛苦的,html 中最轻微的变化都会使你的解析代码完全失效,并需要你重新编写东西。

Taking you question 'title' literally, see my answer to this question for how to grab the raw html using a web url...
Android Dev: How do I extract data from the web and use the data in my app?

I do this and use a 3rd-party class called HtmlCleaner which returns XML which can be searched using XPATH.

As has been said, however, there may well be better ways to do what you want and the comment from CommonsWare in particular is all too true. It's painful and the slightest change in the html can throw your parsing code off completely and require you to re-write things.

七色彩虹 2024-10-16 13:58:19

我快速进行了 Google 搜索,但找不到电影列表的 Google API,尽管您可以查看它们是否在 Google Base API 中公开了这些列表。

一种替代方法是使用 Yahoo 查询语言 API。他们确实有一个 showtimes API,您可以用 Java 查询。以下是您要使用的 YQL 语法:

select * from movies.showtimes

获取所有电影的列表。然后:

select * from movies.showtimes where location='myzip' and name='one of the movies'

您还可以

select * from movies.showtimes where location='myzip' and name in whatever

使用控制台来发现此 API 提供的功能: http://developer.yahoo.com/yql/console/?env=http://datatables.org/alltables.env#h= desc%20movies.showtimes

至于实现,我不是 Java 开发人员(主要是 LAMP 和 .NET),所以我无法为您提供代码示例,但 YQL API 是 RESTful API,因此您只需必须在请求中使用正确的参数来访问 API,它将返回 XML 结果。

希望这能帮助您找到您正在寻找的东西!

I did a quick Google Search and couldn't find a Google API for the cinema listings, although you could see if they expose these in the Google Base API.

One alternative would be using the Yahoo Query Language API. They do have a showtimes API that you can query in Java. Here is the YQL syntax you'd use:

select * from movies.showtimes

To get a list of all movies. Then:

select * from movies.showtimes where location='myzip' and name='one of the movies'

You could also do

select * from movies.showtimes where location='myzip' and name in whatever

You can use the console to discover what this API has to offer here: http://developer.yahoo.com/yql/console/?env=http://datatables.org/alltables.env#h=desc%20movies.showtimes

As far as implementation, I'm not a Java dev (mainly LAMP and .NET) so I can't give you code samples, but the YQL API is a RESTful API, therefore you just have to hit the API with the correct parameters in the request and it will return the XML results.

Hopefully this will help you find what you're looking for!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文