怎么爬取多页网址的内容对应到Excel中(一页网址内容对应一页Excel)

[复制链接]
查看11 | 回复0 | 2021-1-27 05:04:52 | 显示全部楼层 |阅读模式
packagenet.chinaedu.utils;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;importorg.jsoup.Jsoup;importorg.jsoup.nodes.Document;importorg.jsoup.nodes.Element;importorg.jsoup.select.Elements;importnet.chinaedu.bean.Phone;/***使用Jsoup进行爬虫,并且将数据解析出来,封装到Phone对象中,存储到List集合中**@authorAdministrator**/publicclassJsoupUtils{/***得到指定链接的源码,并且转成Document文档对象返回**@paramurl*@return*@throwsIOException*/publicstaticDocumentgetHtmlDocument(Stringurl)throwsIOException{//爬取网页源码,得到文档对象Documentdocument=Jsoup.connect(url).get();//将网页文档对象返回returndocument;}/***解析网页,将解析出来的内容先封装到Phone实体类中,然后保持到List集合中,并且返回**@paramdocument*@return*/publicstaticListgetPhoneList(Documentdocument){//1.定义一个可以存放Phone对象的集合对象ListphoneList=newArrayList();//2.开始解析文档//2.1通过标签的属性得到多个标签元素Elementselements=document.getElementsByAttribute("data-follow-id");//2.2遍历多个标签对象for(inti=0;i -->
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行