# wiki **Repository Path**: npf/wiki ## Basic Information - **Project Name**: wiki - **Description**: 抓取维基百科数据 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2018-03-20 - **Last Updated**: 2021-03-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 一、下载中文维基预料库,导入本地mysql中 1、维基数据抓取方案 https://blog.csdn.net/npf_java/article/details/50196131 2、分析分类关系 3、找出各国武器、人物等总的分类 二、学习webmagic爬虫框架 http://webmagic.io/docs/zh/ 三、springBoot2.0框架搭建 1、解决logback、log4j12日志包冲突问题 ``` us.codecraft webmagic-core ${webmagic-version} org.slf4j slf4j-log4j12 ``` 四、学习笔记 2018-03-29--------------------------------------- 1、分析SQL后发现,下载的wiki数据没有网页上那么全,缺少很多数据 2、重新分析页面 ``` 分类页面分析--------------------------- 1、子分类: $("#mw-subcategories a").each(function(i,t){console.log($(t).text())}); 2、页面: $("#mw-pages a").each(function(i,t){console.log($(t).text())}); 3、父分类: $("#mw-normal-catlinks a").each(function(i,t){console.log($(t).text())}); 详情页面分析-------------------------- 1、标题:#firstHeading $("#firstHeading").text(); "三年式140毫米舰炮[编辑]" 2、介绍:$("#mw-content-text p").text(); 3、属性:$(".infobox") 4、图片:$(".mw-parser-output .image").each(function(i,t){console.log($(t).html())}); ``` 2018-03-27--------------------------------------- 1、昨晚下班前把爬虫程序运行起来,今天早上过来查看的时候,抓取了4W条数据 2、查看数据后,发现质量不行,重复数据太多,利用爬虫工具自动抓取页面URL,数据太过分散,很多不是自己想要的结果! 3、重新分析表结构,通过sql把自己需要的目标名称查询到,然后在利用爬虫进行抓取 2018-03-26--------------------------------------- 1、完善数据源配置 2、编写图片下载代码,解析页面时,将图片下载到本地磁盘 2018-03-24--------------------------------------- 1、根据category、category_outlinks两张表进行联合查询 ``` ####### 根据母分类作为关键字进行查询 : 1043095 母分类 3670146 維基百科分類 SELECT c.id, c.`name`, c1.id, c1.`name` FROM category_inlinks c_in LEFT JOIN category c ON c_in.id = c.id LEFT JOIN category c1 on c_in.inLinks = c1.id where c.`name` like '%母分类%' # 維基百科分類 3670146 select * from category c where c.id = 3670146; # 母分类 1043095 select * from category c where c.id = 1043095; # 根据母分类 查询子分类 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 1043095; # 根据按國家分類 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 56563; # 各國人物 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 48992; # 各國軍事 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 77776; # 各國軍事 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 3119551; # 各国武器 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 1266087; # 中国武器 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 3339457; # 中国武器 select * from category_outlinks c_ou LEFT JOIN category c on c.id = c_ou.outLinks where c_ou.id = 5675838; # 分类和页面之间关系 select * from category_pages c_pg LEFT JOIN page p on c_pg.pages = p.id where p.`name` is not null; select * from category_pages c_pg LEFT JOIN category c on c_pg.id = c.id LEFT JOIN page p on c_pg.pages = p.id where c.name like '东风系列导弹' ; ``` 2、根据维基百科分类页面 ``` 全部分类 https://stats.wikimedia.org/EN/CategoryOverview_ZH_Complete.htm ``` 3、知识图谱学习 ``` 搜信息直接出结果?背后是百度知识图谱的力量 http://science.china.com.cn/2017-08/08/content_39073316.htm ```