"屏幕刮"与Jsoup与元素谁拥有ID [英] "Screen scrape" with Jsoup with element who has ID
问题描述
清一色我想不出如何获取都有一个ID元素的值。我有这个至今
All- I can not figure how to get the value of an element that has an ID. I have this so far
@Override
protected Void doInBackground(Void... unused) {
org.jsoup.nodes.Document doc = null;
try {
doc = Jsoup.connect("http://www3.rtd-denver.com/schedules/getSchedule.action?runboardId=123&routeId=0&routeType=1&serviceType=3").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
docTitle = doc.select("table[id=\"td1-7\"] [class=\"datacell\"]").first().text(); //NOT SURE HERE
return null;
我要的是得到的值< TD ID =td2-6级=DATACELL>
我得到一个强制关闭,当我使用此所以我知道这是不对的。我怎样才能得到这个价值?
What I want is to get the value of <td id="td2-6" class="datacell">
I get a force close when I use this so I know it is not right. How can I get this value?
推荐答案
首先,你应该使用:
doc.select("td#td2-6.datacell").first().text()
或者,由于标识必须是唯一的,只是:
Or, since IDs have to be unique, just:
doc.select("td#td2-6").first().text()
不过,我怀疑这会给你一个强制关闭,除非它发现没有元素(在这种情况下,第()
可能是空)。
如果那些仍然没有工作,因为你没有提供任何LogCat中的错误情况下,检查商务部
为空,在这种情况下,你最初的 Jsoup.connect()
失败。
If those still aren't working, and since you didn't provide any LogCat error context, check if doc
is null, in which case your initial Jsoup.connect()
failed.
这篇关于&QUOT;屏幕刮&QUOT;与Jsoup与元素谁拥有ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!