A
ABAKUS
this code work only some site, why?
Have you some ideas how it make?
import java.io.*;
import java.util.*;
import java.net.*;
import java.io.FileReader;
import java.io.Reader;
import java.io.FileNotFoundException;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
import javax.swing.text.html.parser.ParserDelegator;
import javax.swing.text.MutableAttributeSet;
class Meta {
public static void main(String[] args) throws java.io.FileNotFoundException,
java.io.IOException {
Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "192.168.0.1");
props.put("http.proxyPort", "6588");
System.setProperties(props);
HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback ()
{
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (t == HTML.Tag.META)
{
System.out.println("META inside");
String attrib = (String) a.getAttribute (HTML.Attribute.NAME);
if (attrib != null)
{
System.out.println("NAME : "+attrib);
}
String content =(String) a.getAttribute(HTML.Attribute.CONTENT);
if (content != null)
{
System.out.println("content : "+content);
}
String httpequiv = (String)a.getAttribute(HTML.Attribute.HTTPEQUIV);
if (httpequiv != null)
{
System.out.println("httpequiv : "+httpequiv);
}
}
}
};
for (int counter = args.length - 1; counter >= 0; counter--)
{
Reader reader = getReader(args[counter]);
try{
new ParserDelegator().parse(reader, callback, false);
}
catch (Exception e) {
System.out.println("ERROR IN SITE: "+args[counter]+"Exception"+e);
}
}
}
static Reader getReader(String uri)
throws IOException {
if (uri.startsWith("http:")) {
URLConnection conn=
new URL(uri).openConnection();
return new
InputStreamReader(conn.getInputStream());
} else {
return new FileReader(uri);
}
}
}
Have you some ideas how it make?
import java.io.*;
import java.util.*;
import java.net.*;
import java.io.FileReader;
import java.io.Reader;
import java.io.FileNotFoundException;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
import javax.swing.text.html.parser.ParserDelegator;
import javax.swing.text.MutableAttributeSet;
class Meta {
public static void main(String[] args) throws java.io.FileNotFoundException,
java.io.IOException {
Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "192.168.0.1");
props.put("http.proxyPort", "6588");
System.setProperties(props);
HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback ()
{
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (t == HTML.Tag.META)
{
System.out.println("META inside");
String attrib = (String) a.getAttribute (HTML.Attribute.NAME);
if (attrib != null)
{
System.out.println("NAME : "+attrib);
}
String content =(String) a.getAttribute(HTML.Attribute.CONTENT);
if (content != null)
{
System.out.println("content : "+content);
}
String httpequiv = (String)a.getAttribute(HTML.Attribute.HTTPEQUIV);
if (httpequiv != null)
{
System.out.println("httpequiv : "+httpequiv);
}
}
}
};
for (int counter = args.length - 1; counter >= 0; counter--)
{
Reader reader = getReader(args[counter]);
try{
new ParserDelegator().parse(reader, callback, false);
}
catch (Exception e) {
System.out.println("ERROR IN SITE: "+args[counter]+"Exception"+e);
}
}
}
static Reader getReader(String uri)
throws IOException {
if (uri.startsWith("http:")) {
URLConnection conn=
new URL(uri).openConnection();
return new
InputStreamReader(conn.getInputStream());
} else {
return new FileReader(uri);
}
}
}