zoukankan      html  css  js  c++  java
  • 寒假学习进度-8(热词爬取)

    package hotword;
    
    import java.io.IOException;
    
    import org.jsoup.Connection;
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    
    import dao.Dao;
    
    public class Baidu1 {
        public static void main(String[] args)
        {
            lianjie("https://baike.baidu.com/item/%E6%89%8B%E6%9C%BA/6342");
            
        }
        public static void lianjie(String address)
        {
            String explanation="";
            String title="";
            String url="";
            try {
                Document document=Jsoup.connect(address).get();    
                Elements links=document.getElementsByClass("para");
                Elements reault=links.select("a[href]");
                for(Element link:reault)
                {
                    String linkHref=link.attr("href");
                    //System.out.println(linkHref);
                    String title1=link.text();
                    //System.out.println(title1);
                    title=timu("https://baike.baidu.com"+linkHref);
                    explanation=ex("https://baike.baidu.com"+linkHref);
                    url="https://baike.baidu.com"+linkHref;
                    System.out.println(title);
                    System.out.println(explanation);
                    Dao dao=new Dao();
                    try {
                        //dao.Hotword(title, explanation, url);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
    
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
        public static String timu(String address)
        {
            String name="";
            try {
                Document document=Jsoup.connect(address).get();
                Elements ProjectName=document.getElementsByClass("lemmaWgt-lemmaTitle-title");
                Elements h1=ProjectName.select("h1");
                Elements h2=ProjectName.select("h2");
                name=h1.text()+h2.text();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return name;
        }
        public static String ex(String address)
        {
            String name="";
            try {
                Document document=Jsoup.connect(address).get();
                Elements ProjectName=document.getElementsByClass("lemma-summary");
                name=ProjectName.text();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return name;
        }
    
    }

    截图:

  • 相关阅读:
    Bootstrap留言板界面练习
    Bootstrap 学习
    web | [GXYCTF2019]禁止套娃
    re | [GKCTF2020]WannaReverse
    PE文件结构 | 在PE文件的空白区添加代码
    PE文件结构 | RVA与FOA的转换
    re | [NPUCTF2020]BasicASM
    win32 | WinSock2网络编程 | socket-tcp通信
    web | flask 修饰器实现原理
    运维 | 配置LNMP | 基于docker.ubuntu:16.04
  • 原文地址:https://www.cnblogs.com/liujinxin123/p/12263238.html
Copyright © 2011-2022 走看看