本文介绍了获取从URL表行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Jsoup提取表格单元格中的文本。但是,我得到错误。我想进去&LT文本; P> 每个< TD> 。我将如何做呢?

 文档DOC = Jsoup.connect(URL)得到()。 //这是在零引发错误 - 但是URL是有效的
     。元素表= doc.select(表)第一();
            迭代&其中;组件>迭代=表格。选取(TD)的迭代器()。
            而(iterator.hasNext())
            {
                Log.e(CELLTEXT,iterator.next()文本());
            }
 

HTML:

 <表格边框=0CELLSPACING =0的cellpadding =0WIDTH =400>
          &其中; TR>
            < TD WIDTH =100>
              < P><强>文本1< / STRONG>< / P>
            < / TD>
            < TD WIDTH =200>
              &其中p为H.;文本2&所述; / P>
            < / TD>
          < / TR>
         < TR> ...
 

解决方案

测试你的code在一个简单的Java项目太 - >和

  1. 请问您的网址以的http://
  2. 请您在 AsyncTask的
  3. 请问你的android块上网?
  4. 请发布的堆栈跟踪的或部分的详细信息的有关异常

I'm using Jsoup to extract text from table cells. But I get null error. I would like to get the text inside <p> of each <td>. How would I do that?

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>...
解决方案

Tested your code in a simple java project too --> works

  1. Does your url start with http://?
  2. Do you run your code in an AsyncTask?
  3. Does your android block internet access?
  4. Please post a stacktrace or some more information about the exception

这篇关于获取从URL表行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:04
查看更多