简体   繁体   English

如何从网页(HTML)获取相关信息到我的Android应用程序?

[英]How do i get relevant Information from a Webpage (HTML) into my Android App?

at first i have to say that my english isnt the best so dont blame me for that:). 首先,我不得不说我的英语不是最好的,所以不要为此而怪我:)。

I want to create a Food-App for Android-Systems which is able to get Information (like ingredients,preperation) of Webpages by downloading them through an Asynctask and saving them into a Database (SQLite). 我想为Android系统创建一个Food-App,该应用程序能够通过Asynctask下载网页信息并将其保存到数据库(SQLite)中,从而获取网页的信息(例如成分,预处理)。

I learned to work with JSON - based website and to show the results(after downloading the data) in a ListView. 我学会了使用基于JSON的网站,并在ListView中显示结果(下载数据后)。 Now i have the problem that i dont have JSON in front of me and i have really no clue about how i can write a code which extracts relevant information of HTML - Webpage. 现在,我遇到的问题是我前面没有JSON,而且我真的不知道如何编写可提取HTML-网页相关信息的代码。 Is it even possible? 可能吗?

Sorry if maybe of u may laugh now how unknowing i am but i try to learn:) 抱歉,也许您现在可能会笑,但我却努力学习:)

So i basically know much about Asynctask and Databases. 所以我基本上对Asynctask和数据库了解很多。 But the point is i dont know how to connect them all with my specific problem. 但是重点是我不知道如何将它们与我的特定问题联系起来。

Thank you in advance for all who will deal with my topic! 预先感谢所有将处理我的主题的人!

Try working with jsoup . 尝试使用jsoup Here you can find the jsoup library and full source code. 在这里,您可以找到jsoup库和完整的源代码。

See an example at this site: http://www.vogella.com/tutorials/jsoup/article.html 在此站点上查看示例: http : //www.vogella.com/tutorials/jsoup/article.html


Add jsoup to your project by adding this line to your app build.gradle : 通过将此行添加到您的应用程序build.gradle中 ,将jsoup添加到您的项目中:

compile 'org.jsoup:jsoup:1.10.3'

HTML is a XML based presentation of pages. HTML是基于XML的页面表示。

You can parse it with DOM, if theres repeated tags you may find easier to parse with SAX. 您可以使用DOM来解析它,如果有重复的标签,您可能会发现使用SAX解析起来更容易。 But you will need to parse every information on the site and navigate trough the graph to extract what you want. 但是您将需要解析站点上的所有信息,并通过图形导航以提取所需的内容。

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

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