Android Jsoup,无法检索对象

Android Jsoup,无法检索对象,android,html-parsing,jsoup,Android,Html Parsing,Jsoup,我正在尝试使用JSoupAPI,我的第一次尝试是从google.it检索搜索按钮的文本,并在文本视图中显示它。 我使用了以下代码: protected String doInBackground(Void... params) { Document doc; try { doc = Jsoup.connect("http://www.google.it/").get(); Elements cerca_con_google = doc.select

我正在尝试使用JSoupAPI,我的第一次尝试是从google.it检索搜索按钮的文本,并在文本视图中显示它。 我使用了以下代码:

protected String doInBackground(Void... params) {
    Document doc;
    try {
        doc = Jsoup.connect("http://www.google.it/").get();
        Elements cerca_con_google = doc.select("button[id=gbqfba[aria-label]]");
            int size = cerca_con_google.size();
            Log.i("AAAAAAAAAA", Integer.toString(size));

            if(cerca_con_google != null) {
                return cerca_con_google.text();
            }   
            return "foo";
}

但元素的大小始终为零。也许我对select方法中的选择器查询有错误。。。还是别的什么?

我想你用错了选择器。改为使用按钮[id=gbqfba]。

谷歌根据标题值返回不同的内容,例如用户代理

输出

-- Default header
input - 7
input [ name="ie" value="ISO-8859-1" type="hidden"]
input [ value="it" name="hl" type="hidden"]
input [ name="source" type="hidden" value="hp"]
input [ autocomplete="off" class="lst" value="" title="Cerca con Google" maxlength="2048" name="q" size="57" style="color:#000;margin:0;padding:5px 8px 0 6px;vertical-align:top"]
input [ class="lsb" value="Cerca con Google" name="btnG" type="submit"]
input [ class="lsb" value="Mi sento fortunato" name="btnI" type="submit" onclick="if(this.form.q.value)this.checked=1; else top.location='/doodles/'"]
input [ type="hidden" id="gbv" name="gbv" value="1"]
button - 0
-- Custom header
input - 4
input [ type="hidden" name="output" value="search"]
input [ type="hidden" name="ie" value="UTF-8"]
input [ type="hidden" name="sclient" value="psy-ab"]
input [ id="gbqfq" class="gbqfif" name="q" type="text" autocomplete="off" value=""]
button - 3
button [ id="gbqfb" aria-label="Cerca con Google" class="gbqfb" name="btnG"]
button [ id="gbqfba" aria-label="Cerca con Google" name="btnK" class="gbqfba"]
button [ id="gbqfbb" aria-label="Mi sento fortunato" name="btnI" class="gbqfba" onclick="if(this.form.q.value)this.checked=1;else window.top.location='/doodles/'"]

button#gbqfbb = <button id="gbqfbb" aria-label="Mi sento fortunato" name="btnI" class="gbqfba" onclick="if(this.form.q.value)this.checked=1;else window.top.location='/doodles/'"><span id="gbqfsb">Mi sento fortunato</span></button>

我敢肯定Google会不时地更改元素的ID。这可能就是问题所在。我现在匹配了id元素,它们与几个小时前相同。@giozh这有帮助吗?
-- Default header
input - 7
input [ name="ie" value="ISO-8859-1" type="hidden"]
input [ value="it" name="hl" type="hidden"]
input [ name="source" type="hidden" value="hp"]
input [ autocomplete="off" class="lst" value="" title="Cerca con Google" maxlength="2048" name="q" size="57" style="color:#000;margin:0;padding:5px 8px 0 6px;vertical-align:top"]
input [ class="lsb" value="Cerca con Google" name="btnG" type="submit"]
input [ class="lsb" value="Mi sento fortunato" name="btnI" type="submit" onclick="if(this.form.q.value)this.checked=1; else top.location='/doodles/'"]
input [ type="hidden" id="gbv" name="gbv" value="1"]
button - 0
-- Custom header
input - 4
input [ type="hidden" name="output" value="search"]
input [ type="hidden" name="ie" value="UTF-8"]
input [ type="hidden" name="sclient" value="psy-ab"]
input [ id="gbqfq" class="gbqfif" name="q" type="text" autocomplete="off" value=""]
button - 3
button [ id="gbqfb" aria-label="Cerca con Google" class="gbqfb" name="btnG"]
button [ id="gbqfba" aria-label="Cerca con Google" name="btnK" class="gbqfba"]
button [ id="gbqfbb" aria-label="Mi sento fortunato" name="btnI" class="gbqfba" onclick="if(this.form.q.value)this.checked=1;else window.top.location='/doodles/'"]

button#gbqfbb = <button id="gbqfbb" aria-label="Mi sento fortunato" name="btnI" class="gbqfba" onclick="if(this.form.q.value)this.checked=1;else window.top.location='/doodles/'"><span id="gbqfsb">Mi sento fortunato</span></button>