Apache Tika를 사용하여 HTML 파일에서 <dt>
, <dd>
등과 같은 일부 태그 안에있는 텍스트를 추출하고 싶습니다.Apache Tika를 사용하여 사용자 정의 ContentHandler를 작성하는 방법은 무엇입니까?
그래서이 태그에서 정보를 추출해야하는 맞춤 ContentHandler
을 작성하고 있습니다.
내 맞춤 ContentHandler
코드는 다음과 같습니다. 그것은 아직 완료되지 않았습니다하지만 이미 예상대로 작동하지 :
public class TableContentHandler implements ContentHandler {
// key = abbreviation
// value = information/description for abbreviation
private Map<String, String> abbreviations = new HashMap<String, String>();
// current abbreviation
private String abbreviation = null;
// <dd> element contains abbreviation. So this boolean variable will be set when
// <dd> element is found
private boolean ddElementStarted = false;
// this method is not giving contents within <dd> and </dd> tags
public void characters(char[] chars, int arg1, int arg2) throws SAXException {
if(ddElementStarted) {
System.out.println("chars found...");
}
}
// set boolean ddElementStarted to true to indicate that content handler found
// <dd> element
public void startElement(String arg0, String element, String arg2, Attributes arg3) throws SAXException {
if(element.equalsIgnoreCase("dd")) {
ddElementStarted = true;
}
}
}
여기
내 가정은 즉시 컨텐츠 핸들러 내부 간다 startElement()
방법 및 요소 이름이 dd
나는 안에 내용을 얻기 위해 다음 ddElementStarted = true
을 설정 한 것 때문이다 <dd>
및 </dd>
요소는 characters()
방법으로 확인하겠습니다.
characters()
방법 chars
배열은 :(
을 <dd>
및 </dd>
요소 내의 내용,하지만 작동하지 않습니다 ddElementStarted = true
경우 내가 확인하고 난
- 내가에 갈거야 있는지 알고 싶습니다 올바른 방향?
- Tika를 사용하여 HTML을 구문 분석하는 적절한 방법입니까? 아니면 다른 방법이 있습니까?
- 다른 HTM을 선택해야합니까? JSoup와 같은 L 구문 분석 API? 난 그냥 같은 태그의 몇 가지 정보를 필요로, 난 HTML 페이지의 나머지 부분에 관심이 아니에요.
- Apache Tika에서
XPath
표현식을 지정하는 방법이 있습니까?Tika in Action
도서에서이 정보를 찾을 수 없습니다.