Load just enough HTML to parse out the title.
This commit is contained in:
parent
a780f08ca8
commit
f2792ced87
@ -38,6 +38,9 @@ public class PageDownloader {
|
|||||||
String line = "";
|
String line = "";
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
output += line;
|
output += line;
|
||||||
|
if(TitleParser.retrieveTitle(output) != null) {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -52,6 +55,4 @@ public class PageDownloader {
|
|||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package in.sdqali.sharewithtitle;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class TitleParser {
|
||||||
|
public static String retrieveTitle(String html) {
|
||||||
|
Pattern p = Pattern.compile("<head>.*?<title>(.*?)</title>", Pattern.DOTALL);
|
||||||
|
Matcher m = p.matcher(html);
|
||||||
|
String title = null;
|
||||||
|
while (m.find()) {
|
||||||
|
title = m.group(1);
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
@ -45,14 +45,9 @@ public class TitleRetriever {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String rawHtml) {
|
protected void onPostExecute(String rawHtml) {
|
||||||
Log.d("Share With Title", "On post: " + rawHtml);
|
String title = TitleParser.retrieveTitle(rawHtml);
|
||||||
Pattern p = Pattern.compile("<head>.*?<title>(.*?)</title>.*?</head>", Pattern.DOTALL);
|
|
||||||
Matcher m = p.matcher(rawHtml);
|
|
||||||
String title;
|
|
||||||
String output = urlText;
|
String output = urlText;
|
||||||
while (m.find()) {
|
if (title != null) {
|
||||||
title = m.group(1);
|
|
||||||
Log.d("Share With Title", "Title: " + title);
|
|
||||||
output = title + " " + urlText;
|
output = title + " " + urlText;
|
||||||
}
|
}
|
||||||
callback.onSuccess(output);
|
callback.onSuccess(output);
|
||||||
|
Loading…
Reference in New Issue
Block a user