jsoup爬取表格中的内容

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.lang.*;
import java.text.SimpleDateFormat;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.ecai.entity.ecaibm.FtbInfo;

public class JsoupUtil {
    //胜负彩当前赛事查询
    public static PageData sfcSs(){
         Document doc = null;
         PageData pd = new PageData();
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//设置日期格式
            String  datestr = df.format(new Date());
            pd.put("INSERT_TIME", datestr);
            try {
                doc = Jsoup.connect("http://caipiao.163.com/order/sfc/").get();             
                pd.put("COMPETE_14_ID", UuidUtil.get32UUID());
                 Element singerListDiv = doc.getElementsByAttributeValue("class", "sfc_table").first();
                Elements listDiv = doc.getElementsByAttributeValue("class", "c_fff");
                //得到所有类名为“c_fff”的标签中的内容,以空格分隔存入ss中
                String ss = doc.getElementsByAttributeValue("class", "c_fff").text();
                ss = ss.replace(" ", ",");
                String[] saishi = ss.split(",");    
              //代投截止日期
                String line = doc.getElementsByAttributeValue("id", "bet_time").text();
                line = line.substring(6,22);
                pd.put("DEADLINE",line);
                //期次
                String term = doc.getElementsByAttributeValue("id", "bet_period").text();
                pd.put("TERM",term);
                //赛事
                String ss = doc.getElementsByAttributeValue("class", "c_fff").text();
                ss = ss.replace(" ", ",");
                pd.put("SAISHI",ss);
                //比赛时间
                Elements trs = doc.select("table.sfc_table").select("tr");
                StringBuffer time = new StringBuffer();;
                for(int i = 0;i<trs.size();i++){
                    Elements tds = trs.get(i).select("td");                 
                    if(tds.size()>3){
                        String text = tds.get(2).text();
                        time.append(text+",");
                    }
                }
                String tm = time.toString();
                pd.put("START_TIME",tm);
              //主客球队
                String t = doc.getElementsByAttributeValue("class", "c_2b2b2b").text();
                t = t.replace(" ", ",");
                pd.put("TEAM",t);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return pd;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值