Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How To Read A Web Page  RSS feed

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use getParameter() to read user input, etc.
My question is how to read the content of an existing web site; say, if I type in xyz.com and I am lead to a web page that is all text. And I want to scan the whole page.
Looking forward to have your guidance.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a browser - there is usually a "view Source" option
From a program - look at the classes in the java.net package, especially URL, URLConnection and HttpURLConnection. You can open a connection and slurp up the content as an InputStream.
Bill
 
Chandan Mallesh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can try an example i tried,
--------------
package work_simple;
import java.io.*;
public class FileReaderDemo
{
static String in = "C:\\readme.html";
public static void main(String[] args)
{
try
{
FileReader fr = new FileReader(in);
BufferedReader br= new BufferedReader(fr);
String S;
String Y = "";

while ((S = br.readLine()) != null)
{
Y = Y +" "+ S;
}
System.out.println(Y);
fr.close();
}catch(Exception e)
{
System.out.println("job could not be finished: " + e);
}
System.out.println("job finished");
}

}
--------------
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!