daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package l1;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import org.jsoup.Jsoup;
  6. import org.jsoup.nodes.Document;
  7. import org.jsoup.nodes.Element;
  8. import org.jsoup.select.Elements;
  9.  
  10.  
  11. public class Lab1 {
  12.     public static void main(String[] args) throws IOException {
  13.        
  14.         String keywords = "";
  15.         String robots = "";
  16.         String description = "";
  17.         String link = "";
  18.        
  19.        
  20.        
  21.         String fileName ="/home/student/Downloads/input.html";
  22.         Document doc = Jsoup.parse(new File(fileName), "utf-8");
  23.         Elements divTag = doc.getElementsByTag("title");
  24.        
  25.         Elements metaTags = doc.getElementsByTag("meta");
  26.         for (Element metaTag : metaTags)
  27.         {
  28.             String temp1 = metaTag.attr("content");
  29.             String temp2 = metaTag.attr("name");
  30.             if (temp2.equals("keywords"))
  31.                 keywords = temp1;
  32.             if (temp2.equals("description"))
  33.                 description = temp1;
  34.             if (temp2.equals("robots"))
  35.                 robots = temp1;
  36.            
  37.         }
  38.         System.out.println("Titlul: " + divTag.text());
  39.         System.out.println("Content Description: " + description);
  40.         System.out.println("Content Keywords: " + keywords);
  41.         System.out.println("Content Robots: " + robots);
  42.        
  43.         Elements links = doc.select("ul");
  44.         Elements href = doc.select("a");
  45.        
  46.         for (Element hre : href)
  47.         {
  48.             String absURL = hre.absUrl("href");
  49.             log(absURL);
  50.             log("\n");
  51.         }
  52.         log(link);
  53.        
  54.         }
  55.     private static void log(String msg, String... vals) {
  56.         System.out.println(String.format(msg, vals));
  57.     }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top