What is the most efficient way to take information from any website and use it in an Android APP?

Asked

Viewed 678 times

2

For example: An app that accesses the site https://dolarhoje.com/ and take the value of the current dollar and show in the app. What are the ways to do this?

  • You would have to create/use some library that reads html to make a "Scrap" in html, or look for some API that provides the information you want

  • Could you tell me some library that does that?

  • For android/java I can’t tell you, I’m PHP :/

  • All right, thank you!

2 answers

1

In general you will not get information from reading a website, the most common is to use an API that returns this in a JSON or XML format. The format most used is JSON for being lighter and faster, in which case you can use the library GSON to parse and return a java object

Depending on what you want you can use a webview, explaining in a simplified way, allows applications to open browser windows internally, without having to call' the browser externally, and thus opening another application, consuming more smartphone resources.

As commented, it is also possible to use a library that reads HTML and then you can filter the return and show the data you want, I don’t know any but I know there is

1


The most efficient way is to use a webservice.

But since we don’t live in a perfect world, not always using a webservice is an option. In these cases you can use a library like the jsoup to scroll through HTML and get the information you need.

To consult the site you want with jsoup, it is possible to do:

Document doc = Jsoup.connect("https://dolarhoje.com/").get();
Element newsHeadlines = doc.select("#nacional").first();
String dolarHoje = newsHeadlines.attr("value");
  • That’s kind of what I had in mind, going through an HTML. But I’ll give you an example that’s my personal project... I intend to access the https://sofifa.com/players?keyword= URL where the user would enter the app with a keyword and the site would return with the results. However it can return several results, leaving the return of Jsoup a bit large... this could not be a problem or slow down the app?

  • Slow is relative. Ideally you test and see if the time is acceptable for your use case. In my connection the site you mentioned took between 1.5 and 1.6 seconds to be parsed by jsoup. An alternative to your problem is to create your own webservice as a "cache layer" and consume it in the app. Your webservice would consult the site from time to time and keep in memory or database the information collected for your app.

  • I will study on this side then. Great answer, thank you very much!

  • If a response from the site has helped you, be sure to mark it as accepted so that other users find it more easily. =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.