La copia del código es la siguiente:
trabajo de paquete;
import java.io.bufferedReader;
import java.io.ioException;
import java.io.inputstream;
import java.io.inputstreamreader;
import java.util.regex.matcher;
import java.util.regex.pattern;
importar org.apache.commons.httpclient.defaulthttpmethodcrynler;
importar org.apache.commons.httpclient.httpclient;
importar org.apache.commons.httpclient.httpexception;
importar org.apache.commons.httpclient.httpstatus;
importar org.apache.commons.httpclient.methods.getmethod;
importar org.apache.commons.httpclient.params.httpmethodparams;
clase pública chuanboyi {
public static void main (string [] args) {
// TODO STUB de método generado automático
StringBuffer html = new StringBuffer ();
HttpClient httppclient = new httpClient ();
// crear una instancia de método GET
GetMethod getMethod = new GetMethod ("// www.vevb.com");
// Utilice la política de recuperación predeterminada proporcionada por el sistema
getMethod.getParams (). SetParameter (httpmethodparams.retry_handler, new DeFaulThttpMethodcryHandler ());
intentar{
// ejecutar el método get
int statuscode = httpclient.executemethod (getMethod);
if (statuscode! = httpstatus.sc_ok) {
System.out.println ("El método está mal" + getMethod.getStatUsline ());
}
InputStream ResponseBody = getMethod.getResponseBodyAssTream ();
BufferedReader lector = new BufferedReader (new InputStreamReader (ResponseBody, "UTF-8"));
String line = Reader.readline ();
while (line! = null) {
html.append (línea) .append ("/n");
línea = lector.readline ();
}
lector.close ();
// expresión regular
String regex = "<form de nombre =/" comparación/"[// s // s]+> [// s // s]+</form>.*<Script.*>";
String regexa = "(? <= <li>) [// s // s]+? (? = </li>)";
Pattern Pattern = Pattern.Compile (regex);
Matcher M = Pattern.Matcher (HTML);
StringBuffer str = new StringBuffer ();
int i = 0;
while (m.find ()) {
str.append (m.group ());
}
patrón = patrón.compile (regexa);
m = patrón.matcher (str);
while (m.find ()) {
attrs (m.group ());
i ++;
}
System.out.println ("Hay totales"+i+"¡datos!");
} catch (httpexception e) {
// TODO: Excepción de manejo
System.out.println ("¡Verifique su dirección HTTP proporcionada!");
E.PrintStackTrace ();
} Catch (ioException e) {
// TODO: Excepción de manejo
System.out.println ("¡La línea está mal!");
E.PrintStackTrace ();
} finalmente{
getMethod.ReleaseConnection (); // libera el enlace
}
}
ATTRS vacío estático público (String Str) {
// Obtener la regla de la URL
String REGEXURL = "[AZ]+-[0-9]+//. Html";
// Obtener la expresión regular de nombre
String regexName = "(? <= Title =/") [[// w-// s] [^x00-xff]]+(? =/")";
// Obtener la expresión regular de la imagen
String REGEXPICTURE = "Imágenes.*//. Jpg";
Pattern PatternUrl = Pattern.Compile (RegexUrl);
Pattern PatternName = Pattern.Compile (RegexName);
Pattern PatternPicture = Pattern.Compile (RegexPicture);
Matcher Murl = PatternUrl.Matcher (STR);
Matcher mname = PatternName.Matcher (STR);
Matcher mPicture = PatternPicture.Matcher (STR);
if (mname.find ()) {
System.out.println ("Nombre:"+mname.group ());
}
if (murl.find ()) {
System.out.println ("Link:"+Murl.group ());
}
if (mpicture.find ()) {
System.out.println ("Imagen:"+mpicture.group ());
}
}
}