Ler conteudo entre tags html

4 respostas
xandevieira

Ja procurei mas não encontrei nada que fosse claro.
Preciso ler um arquivo html e pegar conteudo entre tags html
Achei o jtidy, mas não consegui fazer rodar.
Achei tb sobre o url, mas ele atende.

o que me interessa são os dados entre as tags <td></td>

exemplo
<tr bgcolor="#D5BCCD">
<td>1</td>
<td>29/09/2003</td>
<td>18</td>
<td>20</td>
<td>25</td>
<td>23</td>
<td>10</td>
<td>11</td>
<td>24</td>
<td>14</td>
<td>06</td>
<td>02</td>
<td>13</td>
<td>09</td>
<td>05</td>
<td>16</td>
<td>03</td>
<td>0,00</td>
<td>5</td>
<td>154</td>
<td>4645</td>
<td>48807</td>
<td>257593</td>
<td>49.765,82</td>
<td>689,84</td>
<td>10,00</td>
<td>4,00</td>
<td>2,00</td>
<td>0,00</td>
<td>0,00</td>
</tr>
<tr>
<td>2</td>
<td>06/10/2003</td>
<td>23</td>
<td>15</td>
<td>05</td>
<td>04</td>
<td>12</td>
<td>16</td>
<td>20</td>
<td>06</td>
<td>11</td>
<td>19</td>
<td>24</td>
<td>01</td>
<td>09</td>
<td>13</td>
<td>07</td>
<td>0,00</td>
<td>1</td>
<td>184</td>
<td>6232</td>
<td>81252</td>
<td>478188</td>
<td>596.323,70</td>
<td>1.388,95</td>
<td>10,00</td>
<td>4,00</td>
<td>2,00</td>
<td>0,00</td>
<td>0,00</td>
</tr>
</tbody></table>
</body></html>

4 Respostas

pedruhenrik

olha a gambi, rsrs

public class Teste {
	public static void main(String[] args) throws IOException {
		File html = new File("c:\teste.html");

		FileReader reader = new FileReader(html);

		BufferedReader leitor = new BufferedReader(reader);

		String linha = "";

		while ((linha = leitor.readLine()) != null) {
			if (linha.contains("<td>") && linha.contains("</td>")) {
				linha = linha.replaceAll("<td>", "");
				linha = linha.replaceAll("</td>", "");
				System.out.println(linha);

			}
		}
	}
}

att,

xandevieira

Ja ajuda bastante. vlw

A

Galera eu fiz esse esquema de ler um html só que os acentos da página ficaram errados.
Tentei mudar o encoding e não funcionou.

Alguém já passou por isso ?

Abs

caio.ribeiro.pereira

Cara da uma estudada nesse Framework JSOUP

Ele é um parser para HTML bem simples de usar

JSOUP

Criado 30 de junho de 2011
Ultima resposta 21 de mar. de 2012
Respostas 4
Participantes 4