jsoup之解析doc

一、生成document的方法html

        Document course = Jsoup.connect("http://202.114.224.81:7777/pls/wwwbks/bkscjcx.curscopre").cookies(cookies)
                .timeout(3000).post();

或者cookie

subString是html代碼post

        Document course = Jsoup.parse(subString);

 

二、spa

若是html有以下代碼code

<td width="112" height="20" class=td_biaogexian><p align="center">形勢與政策(3)</p></td>

獲得關鍵字htm

        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和textblog

width="112" height="20" class="td_biaogexian"
B1380030
width="112" height="20" class="td_biaogexian"
環境科學與公民環境素質element

Doneget

相關文章
相關標籤/搜索