【问题标题】:jsoup nodes vs elements pull valuesjsoup 节点与元素拉取值
【发布时间】:2013-02-27 02:18:17
【问题描述】:
<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 > a> p >h1") 是什么意思?我没有找到任何好的教程。即使是 jsoup 食谱也没有从更广泛的方面解释这些概念。

我了解了 DOM 概念,如父、兄弟概念。在那里我阅读了有关节点的概念。所以在写东西的同时 元素 e=doc。 .... 或元素 e=doc

我们可以代替创建节点吗?这可行吗,推荐?

我几乎无法从 html 中转义字符串中的值。

【问题讨论】:

    标签: android jsoup


    【解决方案1】:

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

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

    或选择():

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

    【讨论】:

    • 谢谢@user1888162。但这并不是我怀疑的地方。如果我不使用元素,我如何使用节点来实现相同的效果?还有它 doc.select("h3.r > a> p >h1") 是什么意思?我试过了,但我在理解这个概念方面仍然存在错误。
    • 能告诉我如何获取数组中的选项值吗?
    猜你喜欢
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    相关资源
    最近更新 更多