I have the following code:
public class getTag2Html {
public static void main (String[] args) throws IOException {
String tag = "<p>";
URL web = new URL("http://www.insalfonscostafreda.cat/web/");
//comprobar que hi hagi dos paràmetres a l'entrada
System.out.println("Busquem a : "+web + " l'etiqueta p");
// patró de cerca regexp
String pattern = "<" + tag + ".*\/?>";
//Iniciem la connexió
web.openConnection();
BufferedReader in = new BufferedReader( new InputStreamReader(web.openStream()));
File f = new File("eac2.xml");
BufferedWriter bw;
bw = new BufferedWriter(new FileWriter(f));
String inputLine;
while ((inputLine = in.readLine()) != null) {
if(inputLine.contains("<p>")) {
System.out.println(inputLine);
bw.write(inputLine + "\n");
}
}
bw.close();
in.close();
}
}
I do not understand how to use the part:
String pattern = "<" + tag + ".*\/?>";
The program works perfectly for me but I have to use import
java.util.regex.Matcher;
import java.util.regex.Pattern;
The topic is I need to give you two arguments (web page and for example
). and show me the information on the screen.
He does it perfectly, but I do not know how to modify it to be using regex.
Right now the program shows the web page that I gave it as an argument but it only shows the data that are in < p >.
But the statement includes the code part String pattern="<" + tag + ". * \ /? >"; I do not know how to use in my program.
can you help me?
thanks