gpt4 book ai didi

java - 从 url 获取表格行文本

转载 作者:行者123 更新时间:2023-11-30 03:44:50 25 4
gpt4 key购买 nike

我正在使用 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 项目中测试了您的代码 --> 有效

  1. 您的网址是否以 http:// 开头?
  2. 您是否在 AsyncTask 中运行您的代码? ?
  3. 您的 android 是否会阻止互联网访问?
  4. 请发布堆栈跟踪或一些关于异常的更多信息

关于java - 从 url 获取表格行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15157031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com