@Test public void testTitleParsing() throws CaptchaNoJsHtmlParser.CaptchaNoJsV2ParsingError { for (int i = 0; i < inputDataList.size(); ++i) { String inputData = inputDataList.get(i); CaptchaInfo captchaInfo = new CaptchaInfo(); parser.parseChallengeTitle(inputData, captchaInfo); String title = captchaInfo.captchaTitle.getTitle(); assertEquals(resultTitleList.get(i), title); } }
public void parseChallengeTitle( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = challengeTitlePattern.matcher(responseHtml); if (!matcher.find()) { throw new CaptchaNoJsV2ParsingError("Could not parse challenge title " + responseHtml); } CaptchaInfo.CaptchaTitle captchaTitle; try { String title = matcher.group(2); Matcher titleMatcher = challengeTitleBoldPartPattern.matcher(title); if (titleMatcher.find()) { int start = title.indexOf("<strong>"); String firstPart = title.substring(0, start); String boldPart = titleMatcher.group(1); String resultTitle = firstPart + boldPart; captchaTitle = new CaptchaInfo.CaptchaTitle( resultTitle, firstPart.length(), firstPart.length() + boldPart.length()); } else { captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1); } } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge title", error); } if (captchaTitle.isEmpty()) { throw new CaptchaNoJsV2ParsingError("challengeTitle is empty"); } captchaInfo.setCaptchaTitle(captchaTitle); }
CaptchaNoJsHtmlParser { public void parseChallengeTitle( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = challengeTitlePattern.matcher(responseHtml); if (!matcher.find()) { throw new CaptchaNoJsV2ParsingError("Could not parse challenge title " + responseHtml); } CaptchaInfo.CaptchaTitle captchaTitle; try { String title = matcher.group(2); Matcher titleMatcher = challengeTitleBoldPartPattern.matcher(title); if (titleMatcher.find()) { int start = title.indexOf("<strong>"); String firstPart = title.substring(0, start); String boldPart = titleMatcher.group(1); String resultTitle = firstPart + boldPart; captchaTitle = new CaptchaInfo.CaptchaTitle( resultTitle, firstPart.length(), firstPart.length() + boldPart.length()); } else { captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1); } } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge title", error); } if (captchaTitle.isEmpty()) { throw new CaptchaNoJsV2ParsingError("challengeTitle is empty"); } captchaInfo.setCaptchaTitle(captchaTitle); } }
CaptchaNoJsHtmlParser { public void parseChallengeTitle( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = challengeTitlePattern.matcher(responseHtml); if (!matcher.find()) { throw new CaptchaNoJsV2ParsingError("Could not parse challenge title " + responseHtml); } CaptchaInfo.CaptchaTitle captchaTitle; try { String title = matcher.group(2); Matcher titleMatcher = challengeTitleBoldPartPattern.matcher(title); if (titleMatcher.find()) { int start = title.indexOf("<strong>"); String firstPart = title.substring(0, start); String boldPart = titleMatcher.group(1); String resultTitle = firstPart + boldPart; captchaTitle = new CaptchaInfo.CaptchaTitle( resultTitle, firstPart.length(), firstPart.length() + boldPart.length()); } else { captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1); } } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge title", error); } if (captchaTitle.isEmpty()) { throw new CaptchaNoJsV2ParsingError("challengeTitle is empty"); } captchaInfo.setCaptchaTitle(captchaTitle); } CaptchaNoJsHtmlParser(Context context, OkHttpClient okHttpClient); }
CaptchaNoJsHtmlParser { public void parseChallengeTitle( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = challengeTitlePattern.matcher(responseHtml); if (!matcher.find()) { throw new CaptchaNoJsV2ParsingError("Could not parse challenge title " + responseHtml); } CaptchaInfo.CaptchaTitle captchaTitle; try { String title = matcher.group(2); Matcher titleMatcher = challengeTitleBoldPartPattern.matcher(title); if (titleMatcher.find()) { int start = title.indexOf("<strong>"); String firstPart = title.substring(0, start); String boldPart = titleMatcher.group(1); String resultTitle = firstPart + boldPart; captchaTitle = new CaptchaInfo.CaptchaTitle( resultTitle, firstPart.length(), firstPart.length() + boldPart.length()); } else { captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1); } } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge title", error); } if (captchaTitle.isEmpty()) { throw new CaptchaNoJsV2ParsingError("challengeTitle is empty"); } captchaInfo.setCaptchaTitle(captchaTitle); } CaptchaNoJsHtmlParser(Context context, OkHttpClient okHttpClient); @NonNull CaptchaInfo parseHtml(String responseHtml, String siteKey); void parseChallengeTitle(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCParameter(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCheckboxes(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); }
CaptchaNoJsHtmlParser { public void parseChallengeTitle( String responseHtml, CaptchaInfo captchaInfo ) throws CaptchaNoJsV2ParsingError { Matcher matcher = challengeTitlePattern.matcher(responseHtml); if (!matcher.find()) { throw new CaptchaNoJsV2ParsingError("Could not parse challenge title " + responseHtml); } CaptchaInfo.CaptchaTitle captchaTitle; try { String title = matcher.group(2); Matcher titleMatcher = challengeTitleBoldPartPattern.matcher(title); if (titleMatcher.find()) { int start = title.indexOf("<strong>"); String firstPart = title.substring(0, start); String boldPart = titleMatcher.group(1); String resultTitle = firstPart + boldPart; captchaTitle = new CaptchaInfo.CaptchaTitle( resultTitle, firstPart.length(), firstPart.length() + boldPart.length()); } else { captchaTitle = new CaptchaInfo.CaptchaTitle(title, -1, -1); } } catch (Exception error) { throw new CaptchaNoJsV2ParsingError("Error while trying to parse challenge title", error); } if (captchaTitle.isEmpty()) { throw new CaptchaNoJsV2ParsingError("challengeTitle is empty"); } captchaInfo.setCaptchaTitle(captchaTitle); } CaptchaNoJsHtmlParser(Context context, OkHttpClient okHttpClient); @NonNull CaptchaInfo parseHtml(String responseHtml, String siteKey); void parseChallengeTitle(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCParameter(
            String responseHtml,
            CaptchaInfo captchaInfo
    ); void parseCheckboxes(
            String responseHtml,
            CaptchaInfo captchaInfo
    );  }