Fiz um programa que busca o codigo fonte de sitios da internet e depois pesquisa uma determinada palavra que o usuario desejar dentro do codigo encontrado.
O que presciso para concluir esse programa é salvar a busca como texto e a pesquisa ser realizada durante a busca pelo codigo fonte do sitio que o usuario desejar.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//Crawler
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class Prototipo extends JFrame implements ActionListener
{
JTextArea TA;
JTextField TF,TF1;
JButton B1, B2;
JPanel P1,P2;
int posInicial= 0;
public static void main (String args[])
{
JFrame Janela = new Prototipo();
Janela.show();
}
Prototipo()
{
//Janela
setTitle("Busca HTML");
setLocation(100,50);
setSize(600,600);
setResizable(false);
getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
TF = new JTextField(("http://"),20);
TF1= new JTextField(10);
TA = new JTextArea(30,50);
JScrollPane s1 = new JScrollPane(TA);
//Botões
B1 = new JButton("Pesquisa");
B1.addActionListener(this);
B2 = new JButton("Selecionar");
B2.addActionListener(this);
//Area de Texto
P1 = new JPanel();
P1.setLayout(new GridLayout(2,2));
P1.setBackground(new Color(200,200,200));
P2 = new JPanel();
P2.setLayout(new FlowLayout(FlowLayout.CENTER));
P2.setBackground(new Color(200,200,200));
P1.add(TF); P1.add(B1);
P1.add(TF1); P1.add(B2);
P2.add(s1);
getContentPane().add(P1);
getContentPane().add(P2);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==B1)
{
//Implementação Crawler --> Busca Site e Copia o Código HTML
try
{
URL minha_url = new URL (TF.getText());
BufferedReader dado = new BufferedReader( new InputStreamReader( minha_url.openStream()));
String strTemp = "";
while( null != (strTemp = dado.readLine()))
{
TA.append(strTemp+("\n"));
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
if (e.getSource()==B2)
{
//Parser --> Encotrar Palavras no HTML
String pesquisa = TF1.getText();
int res = TA.getText().indexOf(pesquisa, posInicial);
if(res < 0)
{
JOptionPane.showMessageDialog(null, "Texto não encontrado");
posInicial = 0;
}
else
{
TA.requestFocus();
TA.select(res, res + pesquisa.length());
posInicial = res + pesquisa.length();
}
}
}
}
Grato pela atenção