正则表达式获取网页<meta name="description" content=内容
来源:互联网 发布:三维电器接线软件 编辑:程序博客网 时间:2024/05/17 23:57
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test8 {
static int tempa = 10;
public static void main(String[] args) throws IOException {
File file = new File("D:/2cd99ecc9a3b8f2f233cb6d9c17a86b9.jsp");
String htmlReport = readFileAsString(file);
//System.out.println(htmlReport);
//String pattern = "<meta name=\"description\" content=\"(.+?)\r\n(.+?)/>";
String pattern = "name=\"description\" content=\"(.+?)/>";
Pattern p = Pattern.compile(pattern,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcher = p.matcher(htmlReport);
while (matcher.find()) {
String tmp = matcher.group(1);
System.out.println(tmp);
}
}
private static String readFileAsString(File file) throws IOException {
StringBuffer strBuff = new StringBuffer();
String charsetName = "utf-8";
if(file != null && file.exists()){
//InputStream in = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), charsetName);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
while((line = bufferedReader.readLine()) != null){
strBuff.append(line);
strBuff.append("\n");
}
inputStreamReader.close();
bufferedReader.close();
} else {
}
return strBuff.toString();
/*char[] chr = new char[4096];
final StringBuffer buffer = new StringBuffer();
final FileReader reader = new FileReader(file);
try {
while ((len = reader.read(chr)) > 0) {
buffer.append(chr, 0, len);
System.out.println("len=======" + len);
}
} finally {
reader.close();
}*/
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test8 {
static int tempa = 10;
public static void main(String[] args) throws IOException {
File file = new File("D:/2cd99ecc9a3b8f2f233cb6d9c17a86b9.jsp");
String htmlReport = readFileAsString(file);
//System.out.println(htmlReport);
//String pattern = "<meta name=\"description\" content=\"(.+?)\r\n(.+?)/>";
String pattern = "name=\"description\" content=\"(.+?)/>";
Pattern p = Pattern.compile(pattern,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcher = p.matcher(htmlReport);
while (matcher.find()) {
String tmp = matcher.group(1);
System.out.println(tmp);
}
}
private static String readFileAsString(File file) throws IOException {
StringBuffer strBuff = new StringBuffer();
String charsetName = "utf-8";
if(file != null && file.exists()){
//InputStream in = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), charsetName);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
while((line = bufferedReader.readLine()) != null){
strBuff.append(line);
strBuff.append("\n");
}
inputStreamReader.close();
bufferedReader.close();
} else {
}
return strBuff.toString();
/*char[] chr = new char[4096];
final StringBuffer buffer = new StringBuffer();
final FileReader reader = new FileReader(file);
try {
while ((len = reader.read(chr)) > 0) {
buffer.append(chr, 0, len);
System.out.println("len=======" + len);
}
} finally {
reader.close();
}*/
}
}
阅读全文
0 0
- 正则表达式获取网页<meta name="description" content=内容
- 【<meta name="description" content=">】作用
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- <meta name="description" content=">作用讲解
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- 【<meta name="description" content=">】作用讲解
- <meta name="Keywords" description
- 网页中<meta name=" " content=" ">详细解释
- 取出html标签 (适用于html中的<META name=description content="")
- <meta name="" content=">
- <meta name="name" content="string">
- <meta name="name" content="string">
- 6月29日云栖精选夜读:Java、PHP、Python、JS 等开发者都如何绘制统计图
- git排除常用配置,svn与git共存时.gitignore配置
- 【Java并发】相关概念
- Makefile 中的 ifeq 的缩进导致的错误
- Hello World,New Begin!
- 正则表达式获取网页<meta name="description" content=内容
- Spring中加载XML配置文件的方法
- 一.lxml爬取百度贴吧图片
- 你知道思维导图么?
- LINUX打印系统
- Java、PHP、Python、JS 等开发者都如何绘制统计图
- java利用支付宝支付
- 可选参数,被打开窗口的名称
- 有趣的算法问题10——最后一个单词的长度