下面这个是parser的方法,可是有一天,我把我想要的超链接信息获取到了,可是,再想获取纯文本链接是,就不知道下手啦,哪位师哥师姐能帮忙解答一下,感激不敬。。。
public static void main(String args[]) throws Exception {
String url="http://www.67ba.com/";
String encod = dectedEncode(url);//获得页面的编码格式
getHtmlUrls(url, encod);
}
public static void getHtmlUrls(String url, String pageEncoding) {
NodeList nodelist = null;
try {
Parser parser = new Parser(url);
parser.setEncoding(pageEncoding);
nodelist = parser.parse(new NodeClassFilter(LinkTag.class));
} catch (ParserException e) {
e.printStackTrace();
}
if (nodelist != null && nodelist.size() > 0) {
for (int i = 0; i < nodelist.size(); i++){
String urlLink = ((LinkTag)nodelist.elementAt(i)).extractLink();
String urltext = ((LinkTag)nodelist.elementAt(i)).getLinkText();
if(urlLink.indexOf("67ba.com")>1||urlLink.indexOf("jianzhi8.com")>1)
System.out.println( urlLink +""+urltext);
}
}
}
/**
* 检测URL指定的网页的字符集
* @param url
* @return 返回网页的实际编码方式
*/
public static String dectedEncode(String url)
{
String[] encodes = oriEncode.split(",");
for (int i = 0; i < encodes.length; i++) {
if (dectedCode(url, encodes[i])) {
return encodes[i];
}
}
return null;
}
public static void main(String args[]) throws Exception {
String url="http://www.67ba.com/";
String encod = dectedEncode(url);//获得页面的编码格式
getHtmlUrls(url, encod);
}
public static void getHtmlUrls(String url, String pageEncoding) {
NodeList nodelist = null;
try {
Parser parser = new Parser(url);
parser.setEncoding(pageEncoding);
nodelist = parser.parse(new NodeClassFilter(LinkTag.class));
} catch (ParserException e) {
e.printStackTrace();
}
if (nodelist != null && nodelist.size() > 0) {
for (int i = 0; i < nodelist.size(); i++){
String urlLink = ((LinkTag)nodelist.elementAt(i)).extractLink();
String urltext = ((LinkTag)nodelist.elementAt(i)).getLinkText();
if(urlLink.indexOf("67ba.com")>1||urlLink.indexOf("jianzhi8.com")>1)
System.out.println( urlLink +""+urltext);
}
}
}
/**
* 检测URL指定的网页的字符集
* @param url
* @return 返回网页的实际编码方式
*/
public static String dectedEncode(String url)
{
String[] encodes = oriEncode.split(",");
for (int i = 0; i < encodes.length; i++) {
if (dectedCode(url, encodes[i])) {
return encodes[i];
}
}
return null;
}