how to get description/content of web page for given URL.
(Something like Google gives the short description of each resulting link).
I want to do this in my jsp page.
Thank in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Idea: Open the URL as a stream, then HTML-parse the String in its description meta tag.
Grab URL content:
Will need to tweak the above code depending on what your HTML parser library requires (a stream, strings, etc).
HTML-Parse the tags:
You might also be interested in grabbing the title of that page:
Caution: Regular expressions do not seem to work reliably on HTML documents, so a HTML-parser is better.
An example with HTML Parser:
HasAttributeFilterto filter by tags that havename="description"attributeNode—>MetaTagcastingcontentusingMetaTag.getAttribute()Code:
Considerations:
If this is done in a JSP each time the page is loaded, you might get a slowdown due to the network I/O to the URL. Even worse if you do this each time on-the-fly for a page of yours that has many URL links in it, then the slowdown could be massive due to the sequential operation of n URLs. Maybe you can store this information in a database and refresh them as needed instead of doing in it on-the-fly in the JSPs.