前景提要
HDC调试需求开发(15万预算),能者速来!>>>
java编程,利用jsoup提取网页表格,判断表格是否是规则的几行几列,连接数据库建立相应的表格。希望大神能够帮忙解决。
以下是我写的一点代码,能在原基础上修改,实现判断表格的行数和列数。(数据库部分还没有写)
package html2;
import java.io.IOException;
import java.text.ParseException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class test1 {
public static void main(String[] args) throws ParseException {
try{
String url="http://cxxy.seu.edu.cn";
Document document= Jsoup.connect(url).get();
Elements hang = document.select("table").select("tr");
int rows=hang.size();
for (int i = 0; i < rows; i++) {
Elements lie=hang.get(i).select("td");
int lines=lie.size();
for(int j=i;j<lie.size();j++)
{
String texts=lie.get(j).text();
System.out.println(" "+texts);
}
}
}catch (IOException e) {
System.out.println("解析出错!");
e.printStackTrace();
}
}
}