Java读取HTML传人文件,java读取html文件并获取body中所有的标签及内容的案例.pdf
java讀讀取取html文文件件,并并獲獲取取body中中所所有有的的標(biāo)標(biāo)簽簽及及內(nèi)內(nèi)容容的的案案例例
這里的獲取的是html文件中body 中的所有標(biāo)簽以及內(nèi)容
package com.lmt.service.file;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.springframework.stereotype.Component;
import com.lmt.config.UrlConstants;
Component
public class ParseFile {
/**
* 解析html文件
* param file
* return
*/
public String readHtml(File file){
String body = "";
try {
FileInputStream iStream = new FileInputStream(file);
Reader reader = new InputStreamReader(iStream);
BufferedReader htmlReader = new BufferedReader(reader);
String line;
boolean found = false;
while (!found && (line = htmlReader.readLine()) != null) {
if (line.toLowerCase().indexOf("
的前面可能存在空格found = true;
}
}
found = false;
while (!found && (line = htmlReader.readLine()) != null) {
if (line.toLowerCase().indexOf("
found = true;
} else {
// 果存在圖片,則將相對路徑轉(zhuǎn)換為絕對路徑
String lowerCaseLine = line.toLowerCase();
if (lowerCaseLine.contains("src")) {
//這里是定義圖片的訪問路徑
String directory = "D:/test";
// 果路徑名不以反斜杠結(jié)尾,則手動(dòng)添加反斜杠
/*if (!directory.endsWith("\\")) {
directory = directory + "\\";
}*/
// line = line.substring(0, lowerCaseLine.indexOf("src") + 5) + directory +
line.substring(lowerCaseLine.indexOf("src") + 5);
/*String filename = extractFilename(line);
line = line.substri
總結(jié)
以上是生活随笔為你收集整理的Java读取HTML传人文件,java读取html文件并获取body中所有的标签及内容的案例.pdf的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 郁金香汇编代码注入怎么写看雪_世界黑客编
- 下一篇: oracle树结构统计,ORACLE 递