我只想解析 JAVA 中的域名。例如,
http://facebook.com/bartsf
http://www.facebook.com/pages/Shine-Communications/169790283042195
http://graph.facebook.com/100002306245454/picture?width=150&height=150
http://maps.google.com/maps?hl=en&q=37.78353+-122.39579
http://www.google.com/url?sa=X&q=http://www.onlinehaendler-news.de/interviews/1303-abba24-im-spagat-zwischen-haendler-und-kaeuferinteressen.html&ct=ga&cad=CAEQARgAIAAoATABOAFAnqSQjwVIAVAAWABiAmRl&cd=xa_cHWHNG70&usg=AFQjCNFMgnkzqN0fNKMFKz1NTKK1n9Gg9A
这是我正在编写 map reduce 代码的代码。
String[] whiteList={"www.facebook.com","www.google.com"};
UrlValidator urlValidator=new UrlValidator(schemes);
Readfile line by line
for line in file
{
String sCurrentLine=line;
if(sCurrentLine.length()>=3)
{
String tempString=sCurrentLine.substring(0,3);
if(!tempString.equals("192") && !tempString.equals("172") && !tempString.equals("10."))
{
sCurrentLine="http://"+sCurrentLine;
if(urlValidator.isValid(sCurrentLine))//domain filter should be here
{
System.out.println(sCurrentLine);
}
}
tempString="";
}
}
我想过滤域名是 facebook.com 还是 google.com,上面的所有 url 都会被过滤掉。