diff --git a/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/PageDownloader.java b/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/PageDownloader.java index 09abaca..6d4b0e6 100644 --- a/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/PageDownloader.java +++ b/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/PageDownloader.java @@ -38,6 +38,9 @@ public class PageDownloader { String line = ""; while ((line = reader.readLine()) != null) { output += line; + if(TitleParser.retrieveTitle(output) != null) { + return output; + } } } catch (IOException e) { e.printStackTrace(); @@ -52,6 +55,4 @@ public class PageDownloader { } return output; } - - } \ No newline at end of file diff --git a/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/TitleParser.java b/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/TitleParser.java new file mode 100644 index 0000000..6399364 --- /dev/null +++ b/ShareWithTitle/src/main/java/in/sdqali/sharewithtitle/TitleParser.java @@ -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("
.*?