-1

I have a PHP script which prints something like "online" "offline" and a specific number which change in a specific time. I found an example for a http get request, and now I need something like Regex I think, right? :o Does anyone have a tutorial or can give me a simple example?

The code of the request:

String urlString;
urlString = "hear is my url^^";
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
InputStream IS = conn.getInputStream();

The Inputstream IS is the "sourcecode" of the website, right?

Phil
  • 943
  • 2
  • 6
  • 18

2 Answers2

2

You are correct. The IS contains the HTML source. You should consider using a HTML parsing library to extract the data. Regex is going to be brittle. There are many html parsers out there. Look at the below SO post

HTML/XML Parser for Java

Community
  • 1
  • 1
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
0

Actually you dont need to use URLConnection to get the data from PHP script. You can use Jsoup library to get data from PHP script and using this library you can parse the data as you want. You will get it from here

Jsoup API

and here is how to use it.

Cookbook for Jsoup

Pratik
  • 1,531
  • 3
  • 25
  • 57
  • I included the jar of Jsoup and wrote this code Document doc = Jsoup.connect("my url^^").get(); String title = doc.title(); TextView tv = (TextView)findViewById(R.id.testView); tv.setText(title); But my program totally crashes :/ Do you have an idea? – Phil Nov 02 '12 at 14:50
  • What error you are getting? You can try Document doc = Jsoup.parse(new URL("your url"),int timeoutMillis ) instead of "Document doc = Jsoup.connect("my url^^").get() ".... – Pratik Nov 05 '12 at 13:14