I have to write a piece of code that loads a remote web page, search for the links, visit those pages and gather some info from certain tags...
How would you do this? Is the visitor pattern of any help here? If so, how could I use it?
Thanks
I have to write a piece of code that loads a remote web page, search for the links, visit those pages and gather some info from certain tags...
How would you do this? Is the visitor pattern of any help here? If so, how could I use it?
Thanks
Some comments/suggestions
In your case
For you problem,
extractLinkFromPage
, visitLinkAndParseTags
), but IMO, it will be overkill for this simple problem. class WebUtility{ public List<String> parseLinks(String remotePageAddress){ //Parse links } public TageInfo extractTageInfo(String pageURL){ //Extract the Tag information } }
Here the TagInfo
class will be a pojo as per your requirement.
This class is stateless and can be used as singleton
. Optionally you can make the constructor private and method static.
Once you have this, you can invoke parseLinks
to get the links and then loop through the list of links to get the tag information from each link by invoking extractTageInfo
method.