parent
aa337f20f7
commit
f226348515
@ -0,0 +1,8 @@
|
|||||||
|
package com.tamguo.dao;
|
||||||
|
|
||||||
|
import com.tamguo.config.dao.SuperMapper;
|
||||||
|
import com.tamguo.model.CrawlerPaperEntity;
|
||||||
|
|
||||||
|
public interface CrawlerPaperMapper extends SuperMapper<CrawlerPaperEntity>{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.tamguo.dao;
|
||||||
|
|
||||||
|
import com.tamguo.config.dao.SuperMapper;
|
||||||
|
import com.tamguo.model.PaperEntity;
|
||||||
|
|
||||||
|
public interface PaperMapper extends SuperMapper<PaperEntity> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.tamguo.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableName;
|
||||||
|
import com.tamguo.config.dao.SuperEntity;
|
||||||
|
|
||||||
|
@TableName(value="crawler_paper")
|
||||||
|
public class CrawlerPaperEntity extends SuperEntity<CrawlerChapterEntity>{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String questionUrl;
|
||||||
|
|
||||||
|
private String paperId;
|
||||||
|
|
||||||
|
public String getQuestionUrl() {
|
||||||
|
return questionUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuestionUrl(String questionUrl) {
|
||||||
|
this.questionUrl = questionUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getSerialversionuid() {
|
||||||
|
return serialVersionUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaperId() {
|
||||||
|
return paperId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaperId(String paperId) {
|
||||||
|
this.paperId = paperId;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,246 @@
|
|||||||
|
package com.tamguo.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotations.TableName;
|
||||||
|
import com.tamguo.config.dao.SuperEntity;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The persistent class for the tiku_chapter database table.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableName(value="tiku_paper")
|
||||||
|
public class PaperEntity extends SuperEntity<PaperEntity> implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String subjectId;
|
||||||
|
|
||||||
|
private String courseId;
|
||||||
|
|
||||||
|
private String schoolId;
|
||||||
|
|
||||||
|
private String areaId;
|
||||||
|
|
||||||
|
private String createrId;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String questionInfo;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private String year;
|
||||||
|
|
||||||
|
private Integer downHits;
|
||||||
|
|
||||||
|
private Integer openHits;
|
||||||
|
|
||||||
|
private String seoTitle;
|
||||||
|
|
||||||
|
private String seoKeywords;
|
||||||
|
|
||||||
|
private String seoDescription;
|
||||||
|
|
||||||
|
@TableField(value="free")
|
||||||
|
private String free;
|
||||||
|
|
||||||
|
private String point;
|
||||||
|
|
||||||
|
private String money;
|
||||||
|
|
||||||
|
@TableField(exist=false)
|
||||||
|
private String subjectName;
|
||||||
|
|
||||||
|
@TableField(exist=false)
|
||||||
|
private String courseName;
|
||||||
|
|
||||||
|
@TableField(exist=false)
|
||||||
|
private String areaName;
|
||||||
|
|
||||||
|
@TableField(exist=false)
|
||||||
|
private String schoolName;
|
||||||
|
|
||||||
|
public JSONArray getQueInfo(){
|
||||||
|
if(StringUtils.isEmpty(getQuestionInfo())){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSONArray.parseArray(getQuestionInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCourseId() {
|
||||||
|
return courseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourseId(String courseId) {
|
||||||
|
this.courseId = courseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAreaId() {
|
||||||
|
return areaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaId(String areaId) {
|
||||||
|
this.areaId = areaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(String year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getSerialversionuid() {
|
||||||
|
return serialVersionUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSchoolId() {
|
||||||
|
return schoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchoolId(String schoolId) {
|
||||||
|
this.schoolId = schoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDownHits() {
|
||||||
|
return downHits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownHits(Integer downHits) {
|
||||||
|
this.downHits = downHits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getOpenHits() {
|
||||||
|
return openHits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenHits(Integer openHits) {
|
||||||
|
this.openHits = openHits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuestionInfo() {
|
||||||
|
return questionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuestionInfo(String questionInfo) {
|
||||||
|
this.questionInfo = questionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreaterId() {
|
||||||
|
return createrId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreaterId(String createrId) {
|
||||||
|
this.createrId = createrId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoTitle() {
|
||||||
|
return seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoTitle(String seoTitle) {
|
||||||
|
this.seoTitle = seoTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoKeywords() {
|
||||||
|
return seoKeywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoKeywords(String seoKeywords) {
|
||||||
|
this.seoKeywords = seoKeywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeoDescription() {
|
||||||
|
return seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeoDescription(String seoDescription) {
|
||||||
|
this.seoDescription = seoDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCourseName() {
|
||||||
|
return courseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourseName(String courseName) {
|
||||||
|
this.courseName = courseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAreaName() {
|
||||||
|
return areaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaName(String areaName) {
|
||||||
|
this.areaName = areaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSchoolName() {
|
||||||
|
return schoolName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchoolName(String schoolName) {
|
||||||
|
this.schoolName = schoolName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubjectId() {
|
||||||
|
return subjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubjectId(String subjectId) {
|
||||||
|
this.subjectId = subjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubjectName() {
|
||||||
|
return subjectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubjectName(String subjectName) {
|
||||||
|
this.subjectName = subjectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPoint() {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoint(String point) {
|
||||||
|
this.point = point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMoney() {
|
||||||
|
return money;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoney(String money) {
|
||||||
|
this.money = money;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFree() {
|
||||||
|
return free;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFree(String free) {
|
||||||
|
this.free = free;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.tamguo.model.vo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.xuxueli.crawler.annotation.PageFieldSelect;
|
||||||
|
import com.xuxueli.crawler.annotation.PageSelect;
|
||||||
|
import com.xuxueli.crawler.conf.XxlCrawlerConf;
|
||||||
|
|
||||||
|
@PageSelect(cssQuery = "body")
|
||||||
|
public class PaperVo {
|
||||||
|
|
||||||
|
// 试卷URL
|
||||||
|
@PageFieldSelect(cssQuery = ".paperlist .paper-title a", selectType = XxlCrawlerConf.SelectType.ATTR, selectVal = "abs:href")
|
||||||
|
private List<String> paperUrls;
|
||||||
|
|
||||||
|
@PageFieldSelect(cssQuery = ".title-bar .title-inner .paper-title .title")
|
||||||
|
private String paperName;
|
||||||
|
|
||||||
|
@PageFieldSelect(cssQuery = ".quelist-wrap .ques-container .ques-info-wrap .que-type")
|
||||||
|
private List<String> questionInfoTypes;
|
||||||
|
|
||||||
|
@PageFieldSelect(cssQuery = ".quelist-wrap .ques-container .ques-info-wrap .que-info")
|
||||||
|
private List<String> questionInfoTitles;
|
||||||
|
|
||||||
|
@PageFieldSelect(cssQuery = ".view-analyse .view-link", selectType = XxlCrawlerConf.SelectType.ATTR, selectVal = "abs:href")
|
||||||
|
private List<String> questionUrls;
|
||||||
|
|
||||||
|
public String getPaperName() {
|
||||||
|
return paperName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaperName(String paperName) {
|
||||||
|
this.paperName = paperName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getQuestionInfoTypes() {
|
||||||
|
return questionInfoTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuestionInfoTypes(List<String> questionInfoTypes) {
|
||||||
|
this.questionInfoTypes = questionInfoTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPaperUrls() {
|
||||||
|
return paperUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaperUrls(List<String> paperUrls) {
|
||||||
|
this.paperUrls = paperUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getQuestionInfoTitles() {
|
||||||
|
return questionInfoTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuestionInfoTitles(List<String> questionInfoTitles) {
|
||||||
|
this.questionInfoTitles = questionInfoTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getQuestionUrls() {
|
||||||
|
return questionUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuestionUrls(List<String> questionUrls) {
|
||||||
|
this.questionUrls = questionUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
package com.tamguo;
|
||||||
|
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.tamguo.dao.CrawlerPaperMapper;
|
||||||
|
import com.tamguo.dao.PaperMapper;
|
||||||
|
import com.tamguo.model.CrawlerPaperEntity;
|
||||||
|
import com.tamguo.model.PaperEntity;
|
||||||
|
import com.tamguo.model.enums.QuestionType;
|
||||||
|
import com.tamguo.model.vo.PaperVo;
|
||||||
|
import com.xuxueli.crawler.XxlCrawler;
|
||||||
|
import com.xuxueli.crawler.parser.PageParser;
|
||||||
|
import com.xuxueli.crawler.rundata.RunData;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class PaperCrawler {
|
||||||
|
|
||||||
|
// 高考
|
||||||
|
private final String SUBJECT_ID = "gaokao";
|
||||||
|
// 科目
|
||||||
|
private final String COURSE_ID = "likeshuxue";
|
||||||
|
// 110000 北京
|
||||||
|
private final String AREA_ID = "110000";
|
||||||
|
// 年份
|
||||||
|
private final String YEAR = "2018";
|
||||||
|
// 真题试卷 类型(1:真题试卷,2:模拟试卷,3:押题预测,4:名校精品)
|
||||||
|
private final String PAPER_TYPE = "1";
|
||||||
|
// 开始采集的URL
|
||||||
|
private final String START_URL = "https://tiku.baidu.com/tikupc/paperlist/1bfd700abb68a98271fefa04-16-0-2018-37-1-download";
|
||||||
|
|
||||||
|
private RunData runData;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PaperMapper paperMapper;
|
||||||
|
@Autowired
|
||||||
|
private CrawlerPaperMapper crawlerPaperMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void crawler() {
|
||||||
|
XxlCrawler crawler = new XxlCrawler.Builder()
|
||||||
|
.setUrls(START_URL)
|
||||||
|
.setAllowSpread(false)
|
||||||
|
.setFailRetryCount(5)
|
||||||
|
.setThreadCount(1)
|
||||||
|
.setPageParser(new PageParser<PaperVo>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parse(Document html, Element pageVoElement, PaperVo paperVo) {
|
||||||
|
// 解析封装 PageVo 对象
|
||||||
|
String pageUrl = html.baseUri();
|
||||||
|
if(pageUrl.contains("https://tiku.baidu.com/tikupc/paperdetail")) {
|
||||||
|
System.out.println(paperVo.getPaperName());
|
||||||
|
|
||||||
|
PaperEntity paper = new PaperEntity();
|
||||||
|
paper.setSubjectId(SUBJECT_ID);
|
||||||
|
paper.setCourseId(COURSE_ID);
|
||||||
|
paper.setSchoolId("");
|
||||||
|
paper.setAreaId(AREA_ID);
|
||||||
|
paper.setCreaterId("system");
|
||||||
|
paper.setName(paperVo.getPaperName());
|
||||||
|
paper.setYear(YEAR);
|
||||||
|
paper.setFree("0");
|
||||||
|
paper.setSeoTitle(paperVo.getPaperName());
|
||||||
|
paper.setSeoKeywords("");
|
||||||
|
paper.setSeoDescription("");
|
||||||
|
paper.setType(PAPER_TYPE);
|
||||||
|
JSONArray entitys = new JSONArray();
|
||||||
|
// 处理类型问题
|
||||||
|
for(int i=0 ; i<paperVo.getQuestionInfoTypes().size() ; i++) {
|
||||||
|
JSONObject entity = new JSONObject();
|
||||||
|
entity.put("id", i+1);
|
||||||
|
entity.put("name", paperVo.getQuestionInfoTypes().get(i));
|
||||||
|
entity.put("title", paperVo.getQuestionInfoTitles().get(i));
|
||||||
|
QuestionType questionType = QuestionType.getQuestionType(paperVo.getQuestionInfoTypes().get(i));
|
||||||
|
entity.put("type", questionType.getValue());
|
||||||
|
|
||||||
|
|
||||||
|
entitys.add(entity);
|
||||||
|
}
|
||||||
|
paper.setQuestionInfo(entitys.toJSONString());
|
||||||
|
paperMapper.insert(paper);
|
||||||
|
|
||||||
|
// 插入图片
|
||||||
|
for(int i=0 ; i<paperVo.getQuestionUrls().size() ; i++) {
|
||||||
|
CrawlerPaperEntity cp = new CrawlerPaperEntity();
|
||||||
|
cp.setPaperId(paper.getId());
|
||||||
|
cp.setQuestionUrl(paperVo.getQuestionUrls().get(i));
|
||||||
|
crawlerPaperMapper.insert(cp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(pageUrl.contains("https://tiku.baidu.com/tikupc/paperlist")) {
|
||||||
|
for(int i=0 ; i<paperVo.getPaperUrls().size() ; i++) {
|
||||||
|
runData.addUrl(paperVo.getPaperUrls().get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).build();
|
||||||
|
|
||||||
|
runData = crawler.getRunData();
|
||||||
|
// 获取科目
|
||||||
|
crawler.start(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue