![]() |
Network Programming Help.
Hi all.
I'm a second year soft ware engineering student and we've been given an assignment in network programming. The assignment specification is to take a URL as a command line argument, download it scorce, examine all it's links and finally, print out a summary of how many broken links occurred. I've only just started this and I have a problem. I'm un-sure as to how I would find out weather a piece of HTML is actually a link or not. Our lecturer gave us a link to this example. http://www.exampledepot.com/egs/java.../GetLinks.html Now I've never done network programming before and this seems very hard to understand to me as the writer didn't comment the code or list the packages he used. Could anyone give me a brief explanation of how I would test a page to find links.?? I've been able to figure out how to read in a url and print out it's scorce without any problem and I've included this code below. Thanks :). :
//THIS IS JUST A TEST!!!!!!!! |
Re: Network Programming Help.
I would think a normal ping would work, as in if you ping the url, it either is tied to the server or it's not. But then, I don't know that much about networking.
|
Re: Network Programming Help.
You could connect to the server and still have a broken link. That is, the server might return a 404 page, for instance.
Your first step is to parse the page for all links. That's the emphasis of the link you posted. The next step is to follow all the links and see if you get a valid page returned (200 OK, for instance). |
Re: Network Programming Help.
HttpURLConnection has a method called getResponseCode() and returns 200 if its a valid page. Once you parse the links from the HTML source, you can put them into a list and iterate through the list of urls to see if they are valid. Here is a method that you could use. My Java skills are a bit rusty so bare with me.
:
public bool isValidUrl(String urlStr) |
Re: Network Programming Help.
Thanks guys, I got that code in the link to work (after a few hours and about 5 pints of cofee !! :) ). I have all my methods worked out so putting the program together should be a breeze. Thanks :).
|
Re: Network Programming Help.
:
|
| All times are GMT -5. The time now is 3:33 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC