473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

HOWTO open URL

I am trying to open a url and read the data into a string.

for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.

thanks for any help.

Jul 17 '05 #1
6 57871
Do you want all of it put
into one string or do you
want to read it a line at a time?

Phil..

"dave" <no****@nospam.net> wrote in message news:gk****************@fe04.atl2.webusenet.com...
I am trying to open a url and read the data into a string.

for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.

thanks for any help.


Jul 17 '05 #2
All is fine

"Phil" <ry***@ieee.org> wrote in message
news:1BR_a.105374$cF.31350@rwcrnsc53...
Do you want all of it put
into one string or do you
want to read it a line at a time?

Phil..

"dave" <no****@nospam.net> wrote in message
news:gk****************@fe04.atl2.webusenet.com...
I am trying to open a url and read the data into a string.

for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.

thanks for any help.


Jul 17 '05 #3
import java.net.*;
import java.io.*;

public class URLReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.sourceforge.com");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}
}

from http://java.sun.com/docs/books/tutor...eadingURL.html

HTH
sandip

"dave" <no****@nospam.net> wrote in message news:<gk****************@fe04.atl2.webusenet.com>. ..
I am trying to open a url and read the data into a string.

for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.

thanks for any help.

Jul 17 '05 #4
You can do the following

URL url = new URL(urlString);
InputStream in = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ( (aLine = br.readLine()) != null ) {
//do something with aLine
}

Hope this helps,
Daniel Goldman
http://d-goldman.org
Jul 17 '05 #5
Some example working code:
http://www.javapractices.com/Topic147.cjp

dave wrote:
I am trying to open a url and read the data into a string.

for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.

thanks for any help.



Jul 17 '05 #6

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

public class UrlVisit {

/** Creates a new instance of UrlVisit */
public UrlVisit() {
}

public boolean visitWebPage(String UrlToVisit) {

boolean urlVisited = false;
try {
URL url = new URL(UrlToVisit);
URLConnection urlConnection = url.openConnection();
BufferedReader htmlPage = new BufferedReader(new
InputStreamReader(url.openStream()));

String line = "";
while((line = htmlPage.readLine()) != null) {
//do something with the html line
System.out.println(line);
}
htmlPage.close();
urlConnection = null;
urlVisited = true;
} catch(Exception e) {
urlVisited = false;
}
return urlVisited;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
UrlVisit urlVisit = new UrlVisit();
String url = null;
String commstart = " <!-- *********************** ";
String commend = " *********************** -->";
if (args[0] == null) {
url = "http://www.cnn.com";
} else {
url = args[0];
System.out.println(commstart + "Visiting "+ url + commend);
}
if (urlVisit.visitWebPage(url)) {
System.out.println(commstart + url + " visited" + commend);
} else {
System.out.println(commstart + url + " Website not found" +
commend);
}
}
}
"John" <no****@nospam.com> wrote in message
news:RM********************@magma.ca...
Some example working code:
http://www.javapractices.com/Topic147.cjp

dave wrote:
I am trying to open a url and read the data into a string.

for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.

thanks for any help.



Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: martijn | last post by:
Hi There, my vb app can open files. Well, actually my vb app launches word or excell to open them. These files are shared in a network. If somebody else has allready opened that file, you...
4
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or...
4
by: Josef Sachs | last post by:
Is Andrew Kuchling's regex-to-re HOWTO available anywhere? I've found the following (dead) links on various Web pages: http://py-howto.sourceforge.net/regex-to-re/regex-to-re.html...
4
by: Alexander Eisenhuth | last post by:
Hi alltogether, I use ActivePython 2.4.1 , also the debug part from http://ftp.activestate.com/ActivePython/etc/ and VC 6.0 unter Windows XP. I can't figure out howto debug my c++ extension....
5
by: Topper | last post by:
Hello! How to create WebService without IIS and ASP.NET? For example, create WebService for smart device client without ASP.NET/IIS techology. Without ASP.NET and IIS - is a key question!! ...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
2
by: dmitrey | last post by:
hi all, does anyone know howto set title of whole window? (I mean not just area above plot but string in the same line where buttons 'close', 'iconify', 'fullscreen' are situated) Thx, D.
8
by: dmitrey | last post by:
howto check does module 'asdf' exist (is available for import) or no? (without try/cache of course) Thx in advance, D.
1
by: dmitrey | last post by:
howto compile recursively all *.py files to *.pyc (from a directory my_dir)? Thank you in advance, D.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.