Results 1 to 4 of 4
Thread: How to write URL's to a file
- 03-10-2010, 03:35 AM #1
Member
- Join Date
- May 2008
- Location
- Ypsilanti,MI
- Posts
- 22
- Rep Power
- 0
How to write URL's to a file
I am having trouble writing only URL's to a file, ie href tags. I have a program that can write a a given http:// address to a file but i only need to write the href tags. I have tried a bunch of things like looking at all the methods that in the java.net package and nothing really seems helpful. Any help would be great below is what i have thus far. Thanks in advance
Java Code:import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Scanner; public class LinkFinder { public static void main (String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Please enter a URL to search, please include http:// "); String userInput = keyboard.nextLine(); try { String address = userInput; URL u = new URL(address); URLConnection connection = u.openConnection(); InputStream stream = connection.getInputStream(); Scanner in = new Scanner(stream); PrintWriter links = new PrintWriter(new FileWriter("links.txt")); while(in.hasNextLine()) { links.println(in.nextLine()); } links.close(); } catch(FileNotFoundException e) { System.out.println("Cannot find the file."); } catch(MalformedURLException e) { e.getMessage(); } catch(IOException e) { e.getMessage(); } } }
- 03-10-2010, 07:32 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
I don't see where you are even attempting to parse the HTML you've gotten. Try this.
- 03-10-2010, 01:34 PM #3
Member
- Join Date
- May 2008
- Location
- Ypsilanti,MI
- Posts
- 22
- Rep Power
- 0
wow way to be a fucking asshole...letmegoogle that for you really? wow...i have looked at HTML parsing, but isn't that more advanced then what i am looking to do. Unless you are saying thats the only way is to use some complex html parsing code. Btw the top two searches from your search i have already looked at...wtf is this a honda forum? asshole
- 03-10-2010, 02:02 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Wow, what an asshole! Post a code that simply copies a stream and expect someone else to do all your work for you. And No an HTML parser is not going overboard. Parse the thing and pull out the href tags. If you want to try and write the half-page long regex that could also be used for this, then go right ahead and try.
Similar Threads
-
how to write onto a file
By mirage_87 in forum New To JavaReplies: 6Last Post: 09-08-2009, 03:54 PM -
Write to a file in a jar
By Ms.Ranjan in forum New To JavaReplies: 4Last Post: 06-12-2009, 09:27 PM -
How to read and write to a file without taking out the comments in the file
By MAGNUM in forum New To JavaReplies: 5Last Post: 02-05-2009, 10:28 AM -
[SOLVED] File Write in File
By Eku in forum New To JavaReplies: 4Last Post: 10-27-2008, 04:01 AM -
Write to file
By esadeghi in forum Advanced JavaReplies: 1Last Post: 05-21-2008, 01:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks