解决方案 »

  1.   

    把html作为xml文档来看待,用dom4j通过XPath可以轻易找到指定内容
      

  2.   

    dom4j通过XPath我会使用,但取这个位置的值我不会写啊,小弟愚钝,还请各位大侠贴上具体代码吧,谢谢
      

  3.   

    先通过javascript获取其中的值,再通过链接让值作为参数发给服务端接收
      

  4.   

    $.each($("#apDiv6 > table  > tbody >tr "),function(i){

    if($(this).attr("align")=="left"){


    alert($(this).text())
    }




    })
      

  5.   

    使用dom4j 、xpath 。依赖jar文件 dom4j-1.6.1.jar  jaxen-1.1.1.jarpackage com.zf.test;import java.io.StringReader;import org.dom4j.Document;
    import org.dom4j.Node;
    import org.dom4j.io.SAXReader;public class XPATH {
    public static void main(String[] args) throws Exception {
    String str = "<div id=\"apDiv6\">"+
    "<table width=\"100%\" height=\"182\" cellspacing=\"3\" border=\"0\">"+
    "<tbody><tr>"+
    "<td valign=\"middle\" height=\"147\" align=\"center\"><a href=\"#\"><img width=\"211\" height=\"140\" src=\"../images/group/pic04.jpg\" /></a></td>"+
    "</tr>"+
    "<tr>"+
    "<td align=\"left\"><a style=\" color:#213964\"><strong>需要取的内容</strong></a></td>"+
    "</tr>"+
    "</tbody></table>"+
    "</div>";

    SAXReader reader = new SAXReader();
    Document doc = reader.read(new StringReader(str));
    Node node = doc.selectSingleNode("//div/table/tbody/tr/td/a/strong");
    System.out.println(node.getText()); }}方式二: 使用jsoup通过jquery格式搜索html中dom元素   依赖jar文件  jsoup-1.7.1 package com.zf.test;import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;public class JSOUP { public static void main(String[] args) {

    String str = "<div id=\"apDiv6\">"+
    "<table width=\"100%\" height=\"182\" cellspacing=\"3\" border=\"0\">"+
    "<tbody><tr>"+
    "<td valign=\"middle\" height=\"147\" align=\"center\"><a href=\"#\"><img width=\"211\" height=\"140\" src=\"../images/group/pic04.jpg\" /></a></td>"+
    "</tr>"+
    "<tr>"+
    "<td align=\"left\"><a style=\" color:#213964\"><strong>需要取的内容</strong></a></td>"+
    "</tr>"+
    "</tbody></table>"+
    "</div>";

    Document doc = Jsoup.parse(str);

    Elements es =  doc.select("a strong");

    for (Element element : es) {
    System.out.println(element.html());
    }

    }

    }
      

  6.   

    使用dom4j把他看成xml来读取不就ok了String xml=你上面的html脚本字符串
    SAXReader reader=new SAXReader();
    Document doc=reader.read(new StringReader(xml));
    String text=doc.selectSingleNode("/div[@id='apDiv6']//strong[1]").getText();
    System.out.println(text);
      

  7.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head><title></title>
    <meta name="powered-by" content="FineUI v3.2.6 - 基于 ExtJS 的专业 ASP.NET 2.0 控件库 - http://fineui.com/" />
    <link href="/res.axd?css=notheme.css&v=3" rel="stylesheet" text="text/css"/>
    <link href="/res.axd?css=blue.css&v=3" rel="stylesheet" text="text/css"/>
    <link href="/res.axd?css=ux.ux.css&v=635558012233427301" rel="stylesheet" text="text/css"/>
    <style type="text/css">.fineui_x1_panelbase_icon{background: url(/icon/magnifier.png) no-repeat;}</style>
    </head>