1、生成document的方法
Document course = Jsoup.connect("http://202.114.224.81:7777/pls/wwwbks/bkscjcx.curscopre").cookies(cookies)
.timeout(3000).post();
或者
subString是html代码
Document course = Jsoup.parse(subString);
2、
如果html有如下代码
<td width="112" height="20" class=td_biaogexian><p align="center">形势与政策(3)</p></td>
得到关键字
Document course = Jsoup.connect("http://202.114.224.81:7777/pls/wwwbks/bkscjcx.curscopre").cookies(cookies) .timeout(3000).post(); Iterator<Element> elements = course.getElementsByAttributeValue("class", "td_biaogexian").iterator(); for (Iterator iter = elements; iter.hasNext();) { Element element = (Element)iter.next(); System.out.println( element.attributes()); System.out.println(element.text()); }
输出attributes和text
width="112" height="20" class="td_biaogexian"
B1380030
width="112" height="20" class="td_biaogexian"
环境科学与公民环境素质
Done