HTML Webページからすべてのコンテンツワードと、Javaを使用して同じHTML WebページのMETAタグに含まれるすべてのキーワードを取得します。ここJAVAを使用したHTML WebPageのMETAタグからKEYWORDを取得
<html>
<head>
<meta name = "keywords" content = "deception, intricacy, treachery">
</head>
<body>
My very short html document.
<br>
It has just 2 'lines'.
</body>
</html>
内容語は次のとおりです:
たとえば、このHTMLソースコードを考えてみ私は、非常には、は、HTML、文書、それは、は短く持って,ちょうど,行
注:句読点と数字「2」が除外されています。ここ
キーワードは以下のとおりです。詐欺、複雑、私はWebDoc呼ばれ、この目的のためにクラスを作成している裏切り
が、これは私の知る限り取得することができたようです。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Set;
import java.util.TreeSet;
public class WebDoc {
protected URL _url;
protected Set<String> _contentWords;
protected Set<String> _keyWords
public WebDoc(URL paramURL) {
_url = paramURL;
}
public Set<String> getContents() throws IOException {
//URL url = new URL(url);
Set<String> contentWords = new TreeSet<String>();
BufferedReader in = new BufferedReader(new InputStreamReader(_url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
// Process each line.
contentWords.add(RemoveTag(inputLine));
//System.out.println(RemoveTag(inputLine));
}
in.close();
System.out.println(contentWords);
_contentWords = contentWords;
return contentWords;
}
public String RemoveTag(String html) {
html = html.replaceAll("\\<.*?>","");
html = html.replaceAll("&","");
return html;
}
public Set<String> getKeywords() {
//NO IDEA !
return null;
}
public URL getURL() {
return _url;
}
@Override
public String toString() {
return null;
}
}
申し訳ありません。コンテンツのラインを忘れました。 PaŭloEbermannは良い答えを出しました。私はそれがbodyタグに含まれているかどうかを確認するだけでした。さもなければ、頭からも情報を得るでしょう – RedSoxFan