import net.htmlparser.jericho.*;
Source source = new Source(new URL(sourceUrlString));
HtmlDocument htmlDocument = new HtmlDocument(source);
String title = htmlDocument.getTitle();
List<Element> linkElements = htmlDocument.getAllElements("a");
for (Element element : linkElements) {
String href = element.getAttributeValue("href");
System.out.println(href);
}
List<Element> formElements = htmlDocument.getAllElements("form");
for (Element element : formElements) {
String action = element.getAttributeValue("action");
System.out.println(action);
}
String text = htmlDocument.getTextExtractor().setIncludeAttributes(true).toString();
System.out.println(text);
import java.net.*;
import java.util.List;
import net.htmlparser.jericho.*;
public class WebpageParser {
public static void main(String[] args) throws Exception {
Source source = new Source(new URL(sourceUrlString));
HtmlDocument htmlDocument = new HtmlDocument(source);
String title = htmlDocument.getTitle();
List<Element> linkElements = htmlDocument.getAllElements("a");
for (Element element : linkElements) {
String href = element.getAttributeValue("href");
System.out.println(href);
}
List<Element> formElements = htmlDocument.getAllElements("form");
for (Element element : formElements) {
String action = element.getAttributeValue("action");
System.out.println(action);
}
String text = htmlDocument.getTextExtractor().setIncludeAttributes(true).toString();
}
}