Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from a URL?

Tags:

java

android

url

I have data provided in a website and it is presented as in the following image:

enter image description here

This website offers values of some parameters which are updated every while. Now I want to retrieve these data according to the column name and the row number in the Android app, I know how to open http connection. But unfortunately I have no idea from where should I start and how to read the data provided in the image.

like image 392
LetsamrIt Avatar asked Sep 13 '12 11:09

LetsamrIt


People also ask

How can we access the data sent through the URL with GET method?

Read the Data: PHP has $_GET superglobal that accepts all the data from the URL and stores it as an array. Syntax: print_r($_GET); Get data and store in an array with some extra information.

How do I get node js URL data?

Replicating fetch() with 'node-fetch' package js. To install, run npm install node-fetch , and set up your code like this: const fetch = require('node-fetch'); let url = "https://www.reddit.com/r/popular.json"; let settings = { method: "Get" }; fetch(url, settings) . then(res => res.

What is data URL in HTML?

A Data URL is a URI scheme that provides a way to inline data in an HTML document. Say you want to embed a small image. You could go the usual way, upload it to a folder and use the img tag to make the browser reference it from the network: <img src="image.png" />


2 Answers

Unless you have a special data source to work on, you have to read the website's contents then process it manually. Here is a link from the java tutorials on how to read from an URL connection.

import java.net.*;
import java.io.*;

public class URLConnectionReader {
    public static void main(String[] args) throws Exception {
        URL oracle = new URL("http://www.oracle.com/");
        URLConnection yc = oracle.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                                yc.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);
        in.close();
    }
}

EDIT:

If you are behind a proxy you should also set these system properties (to the appropriate values):

System.setProperty("http.proxyHost", "3.182.12.1");
System.setProperty("http.proxyPort", "1111");
like image 189
zeller Avatar answered Sep 25 '22 18:09

zeller


If the data is only clear text and the format of table doesnt change you can parse the entire table, for Example after reading the "------- ..." Line you can parse the values using a scanner:

 Scanner s;
 while ((inputLine = in.readLine()) != null)
 {
   s = new Scanner(input).useDelimiter(" ");
   //Then readthe Values like
   value = s.next()); // add all values in a list or array       
 } 
 s.close();
like image 34
CloudyMarble Avatar answered Sep 24 '22 18:09

CloudyMarble