NoNameCracksInc icon

Jsoup parser

NoNameCracksInc | PRO | 01/17/14 11:45:51 PM UTC | 0 ⭐ | 341 👁️ | Never ⏰ | []
Java |

1.77 KB

|

None

|

0 👍

/

0 👎

import org.jsoup.*;
import java.io.*;
import org.jsoup.nodes.*;
 
public class Analyser
{
    public boolean connected=false;
    public String full_line;
    public String command;
    public Document con;
    
    public static void main(String args[]) throws IOException
    {
        Analyser obj=new Analyser();
        obj.core();
    }
    
    public void core() throws IOException
    {
        BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
 
        connect();      
        do
        {
            command=scan.readLine();
            switches();
        }
        while(!command.equals(":quit"));
    }
    
    public void connect() throws IOException
    {
        BufferedReader get=new BufferedReader(new InputStreamReader(System.in));
        
        do
        {
         full_line=get.readLine();
         
         if(full_line.contains(":connect"))
         {
             int length=full_line.length();
             String website=full_line.substring(10,length);
             con=Jsoup.connect("http://"+website).get();
             connected=true;
             System.out.println("connected.");
             return;
         }
         else
         {
             System.out.println("Wrong syntax.Use command [:connect websitename].");
         }
        }
        while(!full_line.contains(":connect"));
    }
    
    public void switches() throws IOException
    {
        if(connected)
        {
            if(command.contains(":get"))
            {
                if(command.contains("-n"))
                {
                    System.out.println(con.nodeName());
                }   
                
                if(command.contains("-t"))
                {
                    System.out.println(con.tagName());
                }
                
                if(command.contains("-s"))
                {
                    System.out.println(con.html());
                }
                
                if(command.contains("-txt"))
                {
                    System.out.println(con.text());
                }
                if(command.contains("-h"))
                {
                    System.out.println(con.hashCode());
                }
            }
            if(command.contains(":reload"))
            {
                connect();
                return;
            }
        }
    }
}

Comments