-3

I was wondering if there is a way to pull specific data from a website using java (eclipse). For example, stock information from Yahoo Finances or from Bloomberg. I've looked around and have found some resources, but I haven't been able to get them to work, perhaps I'm missing something or they're outdated. If possible, I also want to avoid downloading any external resources, I've read up on JSoup and will consider it more seriously if all else fails.

Thanks for the help.

user3682779
  • 11
  • 1
  • 3

1 Answers1

1

The answer is: yes there are many different ways to pull data from websites.

There are essentially 2 alternatives no matter the programming language (Java, .NET, Perl...):

  1. the website has an API: in this case it will be a REST or SOAP API or perhaps a custom one (REST and SOAP probably account for the vast majority). Check out that website's API documentation if any. Also check out Programmable Web for references.
  2. the website doesn't have an API. You then need to do what you call here as screen-scraping. Essentially you will send a series of HTTP GET or HTTP POST requests as your browser would. The server replies with a response which contains HTML code. From there on, you need to "parse" the HTML to extract the information you need. This will require heavy duty XPath (if the content is XML) or regular expressions (if the content is HTML or text).

Look at Apache HTTP Components to get you started.

If all you want is Finance information, Google has a JSON/REST API for that and there's a question on SO that will help you: How can I get stock quotes using Google Finance API?.

Yahoo also has one and there is also already an question on it in SO: Yahoo Finance All Currencies quote API Documentation

Community
  • 1
  • 1
David Brossard
  • 12,223
  • 6
  • 42
  • 72
  • 1
    "or regular expressions (if the content is HTML..." **No**. [Never use regular expressions to parse HTML](https://stackoverflow.com/a/1732454/1898563). – Michael Aug 25 '17 at 11:06