jsoup节点与元素拉取值

时间:2013-03-11 19:04:25

标签: android jsoup

<div class="eight columns">
<form method="post" action="http://www.way2franchise.com/search/filter_franchise">

<div style="margin-bottom:10px;margin-top:20px;">

<select name="industry" id="industry" class="searchBoxSel" title="Select Industry">

<option value="candies_and_confectioneries">Candies and Confectioneries</option>
<option value="childrens_services"> Children's Services</option>
<option value="sports_and_recreatio">Sports &amp; Recreation</option>
<option value="staffing_franchises">Staffing Franchises</option>

    

<div style="margin-bottom:10px;">
<select name="investment" id="investment" class="searchBoxSel" title="Select     Investment">

<option value="">Select Investment</option>
<option value="2500000">Under Rs.2,500,000</option>
<option value="10000000">Under Rs.10,000,000</option>
<option value="50000000">Under Rs.50,000,000</option>
</select>
</div>


<div style="margin-bottom:10px;">
<select class="searchBoxSel" title="Select State" id="state" name="state">
<option value="">Select State</option>
<option value="Andaman and Nicobar Islands">Andaman and Nicobar</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>

</select>
</div>
</form></div>

    Here, I need to get the option value pair in an array.While testing the code out i executed the following code:

     String q=doc.select("eight columns").text();
     System.out.println(q); 

使用Jsoup选择器语法,我应该将整个代码放入字符串'q'。 但我得到一个空值(logcat)。怎么样?

另外doc.select(“h3.r&gt; a&gt; p&gt; h1”)是指?我没有找到任何关于此的好教程。即使jsoup食谱也没有在更广泛的方面解释这些概念。

我经历了DOM概念,如父,兄弟的概念。我读了关于节点的概念。所以写一些东西时 元素e = doc。 ....或元素e = doc

我们可以替换那些创建节点吗?这是可行的,推荐吗?

我几乎无法从html中查找字符串中的值。

1 个答案:

答案 0 :(得分:0)

如果你想获得类“八列”,你可以使用getElementsByClass()示例:

Elements eightcolumns = doc.getElementsByClass("eight columns");
            String str = eightcolumns.first().text();

或select():

 Elements eightcolumns = doc.select("div.eight columns");
            String str = eightcolumns.first().text();