我正在使用 Jsoup 从表格单元格中提取文本。但我得到 null
错误。我想得到里面的文字 <p>
每个 <td>
.我该怎么做?
Document doc = Jsoup.connect("URL").get(); //this is where Null error is thrown - but the URL is valid
Element table = doc.select("table").first();
Iterator<Element> iterator = table.select("td").iterator();
while(iterator.hasNext())
{
Log.e("CellText", iterator.next().text());
}
HTML:
<table border="0" cellspacing="0" cellpadding="0" width="400">
<tr>
<td width="100">
<p><strong>Text1</strong></p>
</td>
<td width="200">
<p>Text2</p>
</td>
</tr>
<tr>...
最佳答案
也在一个简单的 java 项目中测试了您的代码 --> 有效
- 您的网址是否以
http://
开头? - 您是否在
AsyncTask
中运行您的代码? ? - 您的 android 是否会阻止互联网访问?
- 请发布堆栈跟踪或一些关于异常的更多信息
关于java - 从 url 获取表格行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15157031/