Home > Java > javaTutorial > body text

Detailed example of Jsoup implementing recruitment information query function

Y2J
Release: 2017-05-06 13:12:27
Original
1475 people have browsed it

This article mainly introduces in detail how Jsoup parses HTML to implement recruitment information query function. It has certain reference value. Interested friends can refer to it

jsoup is a Java HTML parsing tool. It can directly parse a URL address and HTML text content. It provides a very low-effort API to retrieve and manipulate data through DOM, CSS, and jQuery-like manipulation methods.

The following is the html information of the recruitment website:

 <p class="newlist_list_content" id="newlist_list_content_table"> 
 <table width="853" class="newlist" cellpadding="0" cellspacing="0">
  <tbody>
  <tr>
  <th class="zwmc"><span>职位名称</span></th>
  <th class="gsmc">公司名称</th> 
  <th class="zwyx">职位月薪</th>
  <th class="gzdd">工作地点</th>
  <th class="gxsj">发布日期</th>
  </tr>
  </tbody>
</table> 

 <table cellpadding="0" cellspacing="0" width="853" class="newlist"> 
  <tbody>
  <tr> 
  <td class="zwmc"> <input type="checkbox" name="vacancyid" value="CC415107716J90250224000_635_1_03_2011_" onclick="zlapply.uncheckAll(&#39;allvacancyid&#39;)" />
  <p style="width:300px;float:left">
   <a style="font-weight: bold" par="ssidkey=y&ss=201&ff=03" href="http://jobs.zhaopin.com/415107716250224.htm" rel="external nofollow" target="_blank">Android 开发工程师</a>
  </p> </td> 

  <td class="gsmc"><a href="http://special.zhaopin.com/pagepublish/41510771/index.html" rel="external nofollow" target="_blank">南京天洑软件有限公司</a></td> 
  <td class="zwyx">面议</td> 
  <td class="gzdd">南京</td> 
  <td class="gxsj"><span>10-24</span><a class="newlist_list_xlbtn" href="javascript:;" rel="external nofollow" ></a></td> 
  </tr> 
  <tr style="display: none" class="newlist_tr_detail"> 
  <td width="833px" style="line-height: 0;" colspan="5"> 
  <p class="newlist_detail"> 
   <p class="clearfix"> 
   <ul> 
   <li class="newlist_deatil_two"><span>地点:南京</span><span>公司性质:民营</span><span>公司规模:20-99人</span><span>经验:1-3年</span><span>学历:大专</span></li>
   <li class="newlist_deatil_last"> 岗位职责: 1、根据需求,基于Android平台进行程序开发; 2、根据产品功能模块设计,编码实现各模块功能,并确保开发质量; 3、编写相关的开发文档。 任职要求: 1、大专以上学历, 计算机或相关专业者优先; 2、2年以上<b>Android开发</b>经验; 3、熟悉Java编...</li> 
   </ul> 
   <dl> 
   <dt> 
   <a href="javascript:void(0)" rel="external nofollow" onclick="return zlapply.searchjob.ajaxApplyBrig1(&#39;CC415107716J90250224000_635&#39;,&#39;ssi&#39;,&#39;_1_03_2012_&#39;)"> <img  src="/assets/images/newlist_sqimg_03.jpg" / alt="Detailed example of Jsoup implementing recruitment information query function" > </a> 
   </dt> 
   <dd>
   <a href="javascript:zlapply.searchjob.saveOne(&#39;CC415107716J90250224000_635&#39;)" rel="external nofollow" ><img  src="/assets/images/newlist_scimg_06.jpg" / alt="Detailed example of Jsoup implementing recruitment information query function" ></a>
   </dd> 
   </dl> 
   </p> 
  </p> </td>
  </tr> 
  </tbody>
</table>
Copy after login

The following uses jsoup to parse the html to obtain recruitment information:

 public static List<HtmlFeed> parse(String html) {
   Document doc = Jsoup.parse(html);
   Elements elements = doc.getElementsByClass("newlist").select("tr");  
   List<HtmlFeed> list=new ArrayList<HtmlFeed>();

  for (Element ele : elements) {
   if (!ele.select("td").toString().equals("")) {
    String job_url = ele.getElementsByClass("zwmc").select("a").attr("href");
    String job = ele.getElementsByClass("zwmc").text();
    String company = ele.getElementsByClass("gsmc").text();
    String addr = ele.getElementsByClass("gzdd").text();
    String date = ele.getElementsByClass("gxsj").text();

     HtmlFeed feed = new HtmlFeed();
 if (!job_url.toString().equals("")&&!job.toString().equals ("")&&!addr.toString().equals("")&&!company.toString().equals("")&&!date.toString().equals("")) {
  feed.setJob_url(job_url.toString());
  feed.setJob(job.toString());
  feed.setAddr(addr.toString());
  feed.setCompany(company.toString());
  feed.setDate(date.toString());

   list.add(feed);
     }
  }

  }
  return list;
 }
Copy after login

The rendering is as follows:

The rendering is as follows :
Detailed example of Jsoup implementing recruitment information query function
Detailed example of Jsoup implementing recruitment information query function
Detailed example of Jsoup implementing recruitment information query function
Detailed example of Jsoup implementing recruitment information query function

##【Related recommendations】

1.

Java Free Video Tutorial

2.

Comprehensive analysis of Java annotations

3.

JFinal Online Manual

The above is the detailed content of Detailed example of Jsoup implementing recruitment information query function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template