(一)爬虫jsoup例子

 

 

 

public class ExampleJsoup {

    
    public static void main(String args[]) {
        try {
            ExampleJsoup exampleJsoup = new ExampleJsoup();
            
            exampleJsoup.Example1();


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    
    
    public static void Example1() throws IOException {
        
        Document doc = Jsoup.connect("https://blog.csdn.net/final0402").get();
        
        //获得网页title
        String title = doc.title();
        System.out.println(  title  );
        
        
        //获得url中的scirpt
        String data = doc.data();
        System.out.println(  data  );
        
        
        String val = doc.val();
        System.out.println( "val  = \n" + val  );
        
        
        //获得url中的请求的地址
        String uri = doc.baseUri();
        System.out.println( "uri  = \n" + uri  );
        
        
        //获得url中的css
        String cssSelector = doc.cssSelector();
        System.out.println( "cssSelector  = \n" + cssSelector  );
        
        
        //获得url中的网页脚本
        String html = doc.html();
        System.out.println( "html  = \n"+ html  );
        
        
        //获得body中内容
        String body = doc.body().text();
        System.out.println( "body  = \n"+  body  );
        
        
        //获得id=asideArchive,dom
        Element content = doc.getElementById("asideArchive");
        System.out.println(  "content  = \n"+ content  );
        
        
        //获得a href集合
        Elements links = doc.select("a[href]");
        System.out.println( "links  = \n"+  content  );
        
        
        //获得所有src集合
        Elements srcs = doc.select("[src]");
        System.out.println( "srcs  = \n"+  srcs  );
        
        
        //获得link href集合
        Elements linkHrefs = doc.select("link[href]");
        System.out.println( "linkhref  = \n"+ linkHrefs   );

 

        //:lt(n) :gt(n)

       //eq(1)


            
    }
    
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

每天走走

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值