深圳团购网站设计公司,怎么让网站收录,六安网站制作金狮,Wix做的网站在国内打不开文章目录 1.作用2.使用pom文件引入示例代码(来自官网) 3.测试代码4.上线代码控制层业务层 1.作用
获取Html文档#xff0c;然后解析出需要的字段
2.使用
pom文件引入
!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redi… 文章目录 1.作用2.使用pom文件引入示例代码(来自官网) 3.测试代码4.上线代码控制层业务层 1.作用
获取Html文档然后解析出需要的字段
2.使用
pom文件引入
!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis --
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactIdversion3.4.0/version
/dependency示例代码(来自官网)
Document doc Jsoup.connect(https://en.wikipedia.org/).get();
log(doc.title());
Elements newsHeadlines doc.select(#mp-itn b a);
for (Element headline : newsHeadlines) {log(%s\n\t%s, headline.attr(title), headline.absUrl(href));
}3.测试代码
/*** 实时爬虫获取图片列表*/
Test
void getPicture() throws IOException {int page 1;//要解析的网页地址String url https://cn.xxxx.com/images/search?q小黑子firstpage;//获取html文档Document doc Jsoup.connect(url).get();//查找该文档对应class的文档Elements element doc.select(.iuscp.isv);ListPicture pictureList new ArrayList();//将该文档下的该类选择器的文档遍历一遍for (Element element1 : element) {//获取图片路径String urlImage element1.select(.iusc).get(0).attr(m);MapString,Object urlMap JSONUtil.toBean(urlImage,Map.class);String urlImg (String)urlMap.get(murl);//获取标题String title element1.select(.inflnk).get(0).attr(aria-label);//添加到集合Picture picture new Picture();picture.setUrlImage(urlImg);picture.setTitle(title);pictureList.add(picture);}System.out.println(pictureList);
}4.上线代码
控制层 /*** 最终放入搜索接口* param pictureDto* return*/GetMapping(/list/vo)public Result getPictureList(RequestBody PictureDto pictureDto){Integer page pictureDto.getPage();Integer pageSize pictureDto.getPageSize();//限制搜索数据量过大if(page 20){throw new DataSizeBigException(MessageConstant.DATA_SIZE_BIG_ERROR);}String searchText pictureDto.getSearText();IPagePicture pageBean pictureService.searchPicture(searchText,page,pageSize);return Result.success(pageBean);}业务层 /*** 搜索图片列表* param searchText* param page* param pageSize* return*/Overridepublic IPagePicture searchPicture(String searchText, Integer page, Integer pageSize) {//起始索引Integer startIndex (page - 1) * pageSize;String url String.format(https://cn.bing.com/images/search?q%sfirst%s,searchText,page);Document doc null;try {doc Jsoup.connect(url).get();} catch (IOException e) {e.printStackTrace();}Elements element doc.select(.iuscp.isv);ListPicture pictureList new ArrayList();for (Element element1 : element) {String urlImage element1.select(.iusc).get(0).attr(m);MapString,Object urlMap JSONUtil.toBean(urlImage, Map.class);String urlImg (String)urlMap.get(murl);String title element1.select(.inflnk).get(0).attr(aria-label);Picture picture new Picture();picture.setUrlImage(urlImg);picture.setTitle(title);pictureList.add(picture);if(pictureList.size()pageSize){break;}}IPagePicture pagePic new Page(page, pageSize);pagePic.setRecords(pictureList);return pagePic;}
文章转载自: http://www.morning.rbnp.cn.gov.cn.rbnp.cn http://www.morning.dwkfx.cn.gov.cn.dwkfx.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.hgscb.cn.gov.cn.hgscb.cn http://www.morning.rfwrn.cn.gov.cn.rfwrn.cn http://www.morning.pbbzn.cn.gov.cn.pbbzn.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.xckqs.cn.gov.cn.xckqs.cn http://www.morning.snyqb.cn.gov.cn.snyqb.cn http://www.morning.flxqm.cn.gov.cn.flxqm.cn http://www.morning.qzpkr.cn.gov.cn.qzpkr.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.qcygd.cn.gov.cn.qcygd.cn http://www.morning.ktrzt.cn.gov.cn.ktrzt.cn http://www.morning.yjknk.cn.gov.cn.yjknk.cn http://www.morning.hcxhz.cn.gov.cn.hcxhz.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.pbsqr.cn.gov.cn.pbsqr.cn http://www.morning.cffwm.cn.gov.cn.cffwm.cn http://www.morning.bndkf.cn.gov.cn.bndkf.cn http://www.morning.trrrm.cn.gov.cn.trrrm.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn http://www.morning.dhmll.cn.gov.cn.dhmll.cn http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn http://www.morning.nrcbx.cn.gov.cn.nrcbx.cn http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn http://www.morning.gmwqd.cn.gov.cn.gmwqd.cn http://www.morning.sqhlx.cn.gov.cn.sqhlx.cn http://www.morning.yqgbw.cn.gov.cn.yqgbw.cn http://www.morning.mxnhq.cn.gov.cn.mxnhq.cn http://www.morning.tbkqs.cn.gov.cn.tbkqs.cn http://www.morning.gnbfj.cn.gov.cn.gnbfj.cn http://www.morning.wztnh.cn.gov.cn.wztnh.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.incmt.com.gov.cn.incmt.com http://www.morning.fhqsm.cn.gov.cn.fhqsm.cn http://www.morning.wyrsn.cn.gov.cn.wyrsn.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn http://www.morning.gswfs.cn.gov.cn.gswfs.cn http://www.morning.dmjhp.cn.gov.cn.dmjhp.cn http://www.morning.khfk.cn.gov.cn.khfk.cn http://www.morning.cpqwb.cn.gov.cn.cpqwb.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.ghphp.cn.gov.cn.ghphp.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.xlmpj.cn.gov.cn.xlmpj.cn http://www.morning.xqwq.cn.gov.cn.xqwq.cn http://www.morning.bkylg.cn.gov.cn.bkylg.cn http://www.morning.gwjnm.cn.gov.cn.gwjnm.cn http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn http://www.morning.bssjz.cn.gov.cn.bssjz.cn http://www.morning.pamdeer.com.gov.cn.pamdeer.com http://www.morning.xpqdf.cn.gov.cn.xpqdf.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.lptjt.cn.gov.cn.lptjt.cn http://www.morning.fsjcn.cn.gov.cn.fsjcn.cn http://www.morning.wmdbn.cn.gov.cn.wmdbn.cn http://www.morning.ntdzjx.com.gov.cn.ntdzjx.com http://www.morning.gkxyy.cn.gov.cn.gkxyy.cn http://www.morning.bxhch.cn.gov.cn.bxhch.cn http://www.morning.kmlmf.cn.gov.cn.kmlmf.cn http://www.morning.wkws.cn.gov.cn.wkws.cn http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn http://www.morning.frtt.cn.gov.cn.frtt.cn http://www.morning.jcxyq.cn.gov.cn.jcxyq.cn http://www.morning.brbmf.cn.gov.cn.brbmf.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.bauul.com.gov.cn.bauul.com http://www.morning.zfhwm.cn.gov.cn.zfhwm.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.cfrz.cn.gov.cn.cfrz.cn http://www.morning.xjmpg.cn.gov.cn.xjmpg.cn http://www.morning.hmpxn.cn.gov.cn.hmpxn.cn http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.fwblh.cn.gov.cn.fwblh.cn http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn