Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package l1;
- import java.io.File;
- import java.io.IOException;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- public class Lab1 {
- public static void main(String[] args) throws IOException {
- String keywords = "";
- String robots = "";
- String description = "";
- String link = "";
- String fileName ="/home/student/Downloads/input.html";
- Document doc = Jsoup.parse(new File(fileName), "utf-8");
- Elements divTag = doc.getElementsByTag("title");
- Elements metaTags = doc.getElementsByTag("meta");
- for (Element metaTag : metaTags)
- {
- String temp1 = metaTag.attr("content");
- String temp2 = metaTag.attr("name");
- if (temp2.equals("keywords"))
- keywords = temp1;
- if (temp2.equals("description"))
- description = temp1;
- if (temp2.equals("robots"))
- robots = temp1;
- }
- System.out.println("Titlul: " + divTag.text());
- System.out.println("Content Description: " + description);
- System.out.println("Content Keywords: " + keywords);
- System.out.println("Content Robots: " + robots);
- Elements links = doc.select("ul");
- Elements href = doc.select("a");
- for (Element hre : href)
- {
- String absURL = hre.absUrl("href");
- log(absURL);
- log("\n");
- }
- log(link);
- }
- private static void log(String msg, String... vals) {
- System.out.println(String.format(msg, vals));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement