/** -------------------------------------------------------------------- **/ private async Task _ProcessPdfPage() { MacroscopeHttpTwoClient Client = this.DocCollection.GetJobMaster().GetHttpClient(); MacroscopeHttpTwoClientResponse ClientResponse = null; string ResponseErrorCondition = null; try { ClientResponse = await Client.Get( this.GetUri(), this.ConfigurePdfPageRequestHeadersCallback, this.PostProcessRequestHttpHeadersCallback ); } catch (MacroscopeDocumentException ex) { this.DebugMsg(string.Format("_ProcessPdfPage :: MacroscopeDocumentException: {0}", ex.Message)); ResponseErrorCondition = ex.Message; this.AddRemark("_ProcessPdfPage", ex.Message); } catch (Exception ex) { this.DebugMsg(string.Format("_ProcessPdfPage :: Exception: {0}", ex.Message)); ResponseErrorCondition = ex.Message; this.AddRemark("_ProcessPdfPage", ex.Message); } if (ClientResponse != null) { MacroscopePdfTools PdfTools; this.ProcessResponseHttpHeaders(Response: ClientResponse); { // Probe Locale //this.Locale = "en"; // Implement locale probing this.Locale = "x-default"; // Implement locale probing this.SetHreflang(HrefLangLocale: this.Locale, Url: this.DocUrl); } { // Canonical this.Canonical = this.DocUrl; this.DebugMsg(string.Format("CANONICAL: {0}", this.Canonical)); } /** Get Response Body ---------------------------------------------- **/ try { byte[] RawData = ClientResponse.GetContentAsBytes(); this.SetContentLength(Length: RawData.Length); PdfTools = new MacroscopePdfTools(PdfData: RawData); if (PdfTools.GetHasError()) { this.AddRemark("CORRUPT_PDF", Observation: PdfTools.GetErrorMessage()); } this.SetWasDownloaded(true); } catch (Exception ex) { this.DebugMsg(string.Format("Exception: {0}", ex.Message)); this.SetStatusCode(HttpStatusCode.BadRequest); PdfTools = null; this.SetContentLength(Length: 0); } /** Title ---------------------------------------------------------- **/ if (PdfTools != null) { string Text = PdfTools.GetTitle(); if (!string.IsNullOrEmpty(Text)) { this.SetTitle(Text, MacroscopeConstants.TextProcessingMode.NO_PROCESSING); this.DebugMsg(string.Format("TITLE: {0}", this.GetTitle())); } else { this.DebugMsg(string.Format("TITLE: {0}", "MISSING")); } } /** Author --------------------------------------------------------- **/ if (PdfTools != null) { string Text = PdfTools.GetAuthor(); if (!string.IsNullOrEmpty(Text)) { this.SetAuthor(AuthorText: Text, ProcessingMode: MacroscopeConstants.TextProcessingMode.NO_PROCESSING); this.DebugMsg(string.Format("AUTHOR: {0}", this.GetAuthor())); } else { this.DebugMsg(string.Format("AUTHOR: {0}", "MISSING")); } } /** Description ---------------------------------------------------- **/ if (PdfTools != null) { string Text = PdfTools.GetDescription(); if (!string.IsNullOrEmpty(Text)) { this.SetDescription(Text, MacroscopeConstants.TextProcessingMode.NO_PROCESSING); this.DebugMsg(string.Format("TITLE: {0}", this.GetDescription())); } else { this.DebugMsg(string.Format("TITLE: {0}", "MISSING")); } } /** Metadata Keywords ---------------------------------------------- **/ if (PdfTools != null) { string Text = PdfTools.GetKeywords(); if (!string.IsNullOrEmpty(Text)) { this.SetKeywords(KeywordsText: Text); this.DebugMsg(string.Format("KEYWORDS: {0}", this.GetKeywords())); } else { this.DebugMsg(string.Format("KEYWORDS: {0}", "MISSING")); } } /** Body Text ------------------------------------------------------ **/ if (PdfTools != null) { this.SetBodyText(Text: ""); if (PdfTools.GetHasError()) { this.AddRemark("PDF_ERROR", Observation: PdfTools.GetErrorMessage()); } else { string Text = PdfTools.GetTextAsString(); if (!string.IsNullOrEmpty(Text)) { this.SetDocumentText(Text: Text); this.SetBodyText(Text: Text); } } this.DebugMsg(string.Format("BODY TEXT: {0}", this.GetBodyTextRaw())); } /** Data Extractors ------------------------------------------------ **/ if (!string.IsNullOrEmpty(this.GetBodyTextRaw())) { if (MacroscopePreferencesManager.GetDataExtractorsEnable()) { if (MacroscopePreferencesManager.GetDataExtractorsApplyToPdf()) { string Text = this.GetBodyTextRaw(); this.ProcessGenericDataExtractors(GenericText: Text); } } } /** Out Links Text ------------------------------------------------- **/ if (this.GetDocumentTextRawLength() > 0) { if (this.GetIsInternal()) { string Text = this.GetDocumentTextRaw(); this.ProcessPureTextOutlinks(TextDoc: Text, LinkType: MacroscopeConstants.InOutLinkType.PDF); } } /** Out Links in Annotations --------------------------------------- **/ if (this.GetIsInternal() && (this.GetDocumentTextRawLength() > 0)) { List <KeyValuePair <string, string> > AnnotationOutLinks = PdfTools.GetOutLinks(); // TODO: Implement extraction of text that underlies the link annotation foreach (KeyValuePair <string, string> AnnotationOutLinkPair in AnnotationOutLinks) { MacroscopeHyperlinkOut HyperlinkOut = null; string AnnotationOutLinkUrlAbs; AnnotationOutLinkUrlAbs = MacroscopeHttpUrlUtils.MakeUrlAbsolute( BaseHref: this.BaseHref, BaseUrl: this.DocUrl, Url: AnnotationOutLinkPair.Key ); HyperlinkOut = this.HyperlinksOut.Add(LinkType: MacroscopeConstants.HyperlinkType.PDF, UrlTarget: AnnotationOutLinkUrlAbs); HyperlinkOut.SetRawTargetUrl(TargetUrl: AnnotationOutLinkUrlAbs); HyperlinkOut.SetAltText(AnnotationOutLinkPair.Value); HyperlinkOut.SetAnchorText(AnnotationOutLinkPair.Value); HyperlinkOut.SetTitle(AnnotationOutLinkPair.Value); HyperlinkOut.SetDoFollow(); HyperlinkOut.SetMethod(Method: "GET"); this.AddDocumentOutlink(AbsoluteUrl: AnnotationOutLinkUrlAbs, LinkType: MacroscopeConstants.InOutLinkType.PDF, Follow: true); } } /** ---------------------------------------------------------------- **/ } if (ResponseErrorCondition != null) { this.ProcessErrorCondition(ResponseErrorCondition); } }
/**************************************************************************/ public void SetPrefsFormControlFields() { { // Configure Display Options this.checkBoxPauseDisplayDuringScan.Checked = MacroscopePreferencesManager.GetPauseDisplayDuringScan(); this.checkBoxShowProgressDialogues.Checked = MacroscopePreferencesManager.GetShowProgressDialogues(); } { //Configure Form Fields /** Spidering Control ---------------------------------------------- **/ this.numericUpDownDepth.Minimum = -1; this.numericUpDownDepth.Maximum = 10000; this.numericUpDownPageLimit.Minimum = -1; this.numericUpDownPageLimit.Maximum = 10000; this.numericUpDownCrawlDelay.Minimum = 0; this.numericUpDownCrawlDelay.Maximum = 60; this.numericUpDownMaxRetries.Minimum = 0; this.numericUpDownMaxRetries.Maximum = 10; } { /** WebProxy Options ----------------------------------------------- **/ this.comboBoxProxyType.SelectedIndex = (int)MacroscopePreferencesManager.GetProxyType(); /** Server Certificate Options --------------------------------------- **/ this.checkBoxServerCertificateValidation.Checked = MacroscopePreferencesManager.GetServerCertificateValidation(); /** Spidering Control ---------------------------------------------- **/ this.numericUpDownMaxThreads.Value = MacroscopePreferencesManager.GetMaxThreads(); this.numericUpDownDepth.Value = MacroscopePreferencesManager.GetDepth(); this.numericUpDownPageLimit.Value = MacroscopePreferencesManager.GetPageLimit(); this.numericUpDownCrawlDelay.Value = MacroscopePreferencesManager.GetCrawlDelay(); this.numericUpDownRequestTimeout.Value = (Decimal)MacroscopePreferencesManager.GetRequestTimeout(); this.numericUpDownMaxRetries.Value = (Decimal)MacroscopePreferencesManager.GetMaxRetries(); this.checkBoxCrawlStrictUrlCheck.Checked = MacroscopePreferencesManager.GetCrawlStrictUrlCheck(); this.checkBoxCheckExternalLinks.Checked = MacroscopePreferencesManager.GetCheckExternalLinks(); this.checkBoxFetchExternalLinks.Checked = MacroscopePreferencesManager.GetFetchExternalLinks(); this.checkBoxFollowRobotsProtocol.Checked = MacroscopePreferencesManager.GetFollowRobotsProtocol(); this.checkBoxFollowSitemapLinks.Checked = MacroscopePreferencesManager.GetFollowSitemapLinks(); this.checkBoxProbeHumansText.Checked = MacroscopePreferencesManager.GetProbeHumansText(); this.checkBoxCheckRedirects.Checked = MacroscopePreferencesManager.GetCheckRedirects(); this.checkBoxFollowRedirects.Checked = MacroscopePreferencesManager.GetFollowRedirects(); this.checkBoxFollowNoFollow.Checked = MacroscopePreferencesManager.GetFollowNoFollow(); this.checkBoxIgnoreQueries.Checked = MacroscopePreferencesManager.GetIgnoreQueries(); this.checkBoxIgnoreHashFragments.Checked = MacroscopePreferencesManager.GetIgnoreHashFragments(); this.checkBoxFollowCanonicalLinks.Checked = MacroscopePreferencesManager.GetFollowCanonicalLinks(); this.checkBoxFollowAlternateLinks.Checked = MacroscopePreferencesManager.GetFollowAlternateLinks(); this.checkBoxFollowHrefLangLinks.Checked = MacroscopePreferencesManager.GetFollowHrefLangLinks(); this.checkBoxDowncaseLinks.Checked = MacroscopePreferencesManager.GetDowncaseLinks(); this.checkBoxFetchStylesheets.Checked = MacroscopePreferencesManager.GetFetchStylesheets(); this.checkBoxFetchJavascripts.Checked = MacroscopePreferencesManager.GetFetchJavascripts(); this.checkBoxFetchImages.Checked = MacroscopePreferencesManager.GetFetchImages(); this.checkBoxFetchAudio.Checked = MacroscopePreferencesManager.GetFetchAudio(); this.checkBoxFetchVideo.Checked = MacroscopePreferencesManager.GetFetchVideo(); this.checkBoxFetchXml.Checked = MacroscopePreferencesManager.GetFetchXml(); this.checkBoxFetchBinaries.Checked = MacroscopePreferencesManager.GetFetchBinaries(); this.checkBoxScanSitesInList.Checked = MacroscopePreferencesManager.GetScanSitesInList(); this.checkBoxProbeParentFolderUrls.Checked = MacroscopePreferencesManager.GetProbeParentFolderUrls(); this.checkBoxProbeHead404sWithGet.Checked = MacroscopePreferencesManager.GetProbeHead404sWithGet(); /** Analysis Options ----------------------------------------------- **/ this.checkBoxResolveAddresses.Checked = MacroscopePreferencesManager.GetResolveAddresses(); this.checkBoxCheckHreflangs.Checked = MacroscopePreferencesManager.GetCheckHreflangs(); this.checkBoxDetectLanguage.Checked = MacroscopePreferencesManager.GetDetectLanguage(); this.checkBoxProcessStylesheets.Checked = MacroscopePreferencesManager.GetProcessStylesheets(); this.checkBoxProcessJavascripts.Checked = MacroscopePreferencesManager.GetProcessJavascripts(); this.checkBoxProcessImages.Checked = MacroscopePreferencesManager.GetProcessImages(); this.checkBoxProcessPdfs.Checked = MacroscopePreferencesManager.GetProcessPdfs(); this.checkBoxProcessAudio.Checked = MacroscopePreferencesManager.GetProcessAudio(); this.checkBoxProcessVideo.Checked = MacroscopePreferencesManager.GetProcessVideo(); this.checkBoxProcessXml.Checked = MacroscopePreferencesManager.GetProcessXml(); this.checkBoxProcessBinaries.Checked = MacroscopePreferencesManager.GetProcessBinaries(); this.numericUpDownRedirectChainsMaxHops.Value = MacroscopePreferencesManager.GetRedirectChainsMaxHops(); this.checkBoxWarnAboutInsecureLinks.Checked = MacroscopePreferencesManager.GetWarnAboutInsecureLinks(); this.checkBoxEnableTextIndexing.Checked = MacroscopePreferencesManager.GetEnableTextIndexing(); this.checkBoxCaseSensitiveTextIndexing.Checked = MacroscopePreferencesManager.GetCaseSensitiveTextIndexing(); this.checkBoxDisregardHtml5ElementNav.Checked = MacroscopePreferencesManager.GetDisregardHtml5ElementNav(); this.checkBoxDisregardHtml5ElementHeader.Checked = MacroscopePreferencesManager.GetDisregardHtml5ElementHeader(); this.checkBoxDisregardHtml5ElementFooter.Checked = MacroscopePreferencesManager.GetDisregardHtml5ElementFooter(); this.checkBoxDetectQrCodeInImage.Checked = MacroscopePreferencesManager.GetDetectQrCodeInImage(); /** SEO Options ---------------------------------------------------- **/ this.numericUpDownTitleMinLen.Value = MacroscopePreferencesManager.GetTitleMinLen(); this.numericUpDownTitleMaxLen.Value = MacroscopePreferencesManager.GetTitleMaxLen(); this.numericUpDownTitleMinWords.Value = MacroscopePreferencesManager.GetTitleMinWords(); this.numericUpDownTitleMaxWords.Value = MacroscopePreferencesManager.GetTitleMaxWords(); this.numericUpDownTitleMaxPixelWidth.Value = MacroscopePreferencesManager.GetTitleMaxPixelWidth(); this.numericUpDownDescriptionMinLen.Value = MacroscopePreferencesManager.GetDescriptionMinLen(); this.numericUpDownDescriptionMaxLen.Value = MacroscopePreferencesManager.GetDescriptionMaxLen(); this.numericUpDownDescriptionMinWords.Value = MacroscopePreferencesManager.GetDescriptionMinWords(); this.numericUpDownDescriptionMaxWords.Value = MacroscopePreferencesManager.GetDescriptionMaxWords(); this.numericUpDownMaxHeadingDepth.Value = MacroscopePreferencesManager.GetMaxHeadingDepth(); this.checkBoxAnalyzeKeywordsInText.Checked = MacroscopePreferencesManager.GetAnalyzeKeywordsInText(); this.checkBoxAnalyzeTextReadability.Checked = MacroscopePreferencesManager.GetAnalyzeTextReadability(); this.comboBoxAnalyzeTextReadabilityEnglishAlgorithm.SelectedIndex = (int)MacroscopePreferencesManager.GetAnalyzeTextReadabilityEnglishAlgorithm(); this.checkBoxEnableLevenshteinDeduplication.Checked = MacroscopePreferencesManager.GetEnableLevenshteinDeduplication(); this.comboBoxLevenshteinAnalysisLevel.SelectedIndex = (int)MacroscopePreferencesManager.GetLevenshteinAnalysisLevel(); this.numericUpDownMaxLevenshteinSizeDifference.Value = MacroscopePreferencesManager.GetMaxLevenshteinSizeDifference(); this.numericUpDownMaxLevenshteinDistance.Value = MacroscopePreferencesManager.GetMaxLevenshteinDistance(); this.checkBoxAnalyzeClickPaths.Checked = MacroscopePreferencesManager.GetAnalyzeClickPaths(); // TODO: Finish implementing click path analysis: #if DEBUG this.groupBoxPageNavigationAnalysis.Visible = true; #else this.groupBoxPageNavigationAnalysis.Visible = false; #endif /** Custom Filter Options ------------------------------------------ **/ this.checkBoxCustomFiltersEnable.Checked = MacroscopePreferencesManager.GetCustomFiltersEnable(); this.numericUpDownCustomFiltersMaxItems.Value = MacroscopePreferencesManager.GetCustomFiltersMaxItems(); this.checkBoxCustomFiltersApplyToHtml.Checked = MacroscopePreferencesManager.GetCustomFiltersApplyToHtml(); this.checkBoxCustomFiltersApplyToCss.Checked = MacroscopePreferencesManager.GetCustomFiltersApplyToCss(); this.checkBoxCustomFiltersApplyToJavascripts.Checked = MacroscopePreferencesManager.GetCustomFiltersApplyToJavascripts(); this.checkBoxCustomFiltersApplyToText.Checked = MacroscopePreferencesManager.GetCustomFiltersApplyToText(); this.checkBoxCustomFiltersApplyToXml.Checked = MacroscopePreferencesManager.GetCustomFiltersApplyToXml(); /** Extractor Options ---------------------------------------------- **/ this.checkBoxDataExtractorsEnable.Checked = MacroscopePreferencesManager.GetDataExtractorsEnable(); this.checkBoxDataExtractorsCleanWhiteSpace.Checked = MacroscopePreferencesManager.GetDataExtractorsCleanWhiteSpace(); this.numericUpDownDataExtractorsMaxItemsCssSelectors.Value = MacroscopePreferencesManager.GetDataExtractorsMaxItemsCssSelectors(); this.numericUpDownDataExtractorsMaxItemsRegexes.Value = MacroscopePreferencesManager.GetDataExtractorsMaxItemsRegexes(); this.numericUpDownDataExtractorsMaxItemsXpaths.Value = MacroscopePreferencesManager.GetDataExtractorsMaxItemsXpaths(); this.checkBoxDataExtractorsApplyToHtml.Checked = MacroscopePreferencesManager.GetDataExtractorsApplyToHtml(); this.checkBoxDataExtractorsApplyToCss.Checked = MacroscopePreferencesManager.GetDataExtractorsApplyToCss(); this.checkBoxDataExtractorsApplyToJavascripts.Checked = MacroscopePreferencesManager.GetDataExtractorsApplyToJavascripts(); this.checkBoxDataExtractorsApplyToText.Checked = MacroscopePreferencesManager.GetDataExtractorsApplyToText(); this.checkBoxDataExtractorsApplyToPdf.Checked = MacroscopePreferencesManager.GetDataExtractorsApplyToPdf(); this.checkBoxDataExtractorsApplyToXml.Checked = MacroscopePreferencesManager.GetDataExtractorsApplyToXml(); /** Export Options ------------------------------------------------- **/ this.checkBoxSitemapIncludeLinkedPdfs.Checked = MacroscopePreferencesManager.GetSitemapIncludeLinkedPdfs(); /** Ignore Errors Settings ----------------------------------------- **/ this.checkBoxIgnoreErrors410.Checked = MacroscopePreferencesManager.GetIgnoreErrors410(); this.checkBoxIgnoreErrors451.Checked = MacroscopePreferencesManager.GetIgnoreErrors451(); } }
/**************************************************************************/ public bool CanApplyDataExtractorsToDocument ( MacroscopeDocument msDoc ) { bool CanApply = true; if ( ( msDoc == null ) || ( msDoc.GetIsRedirect() ) || ( msDoc.GetStatusCode() != HttpStatusCode.OK ) || ( !msDoc.GetIsInternal() ) ) { CanApply = false; } else { if ( !( msDoc.IsDocumentType( Type: MacroscopeConstants.DocumentType.HTML ) || msDoc.IsDocumentType( Type: MacroscopeConstants.DocumentType.CSS ) || msDoc.IsDocumentType( Type: MacroscopeConstants.DocumentType.JAVASCRIPT ) || msDoc.IsDocumentType( Type: MacroscopeConstants.DocumentType.PDF ) || msDoc.IsDocumentType( Type: MacroscopeConstants.DocumentType.TEXT ) || msDoc.IsDocumentType( Type: MacroscopeConstants.DocumentType.XML ) ) ) { CanApply = false; } else { switch ( msDoc.GetDocumentType() ) { case MacroscopeConstants.DocumentType.HTML: if ( !MacroscopePreferencesManager.GetDataExtractorsApplyToHtml() ) { CanApply = false; } break; case MacroscopeConstants.DocumentType.CSS: if ( !MacroscopePreferencesManager.GetDataExtractorsApplyToCss() ) { CanApply = false; } break; case MacroscopeConstants.DocumentType.JAVASCRIPT: if( !MacroscopePreferencesManager.GetDataExtractorsApplyToJavascripts() ) { CanApply = false; } break; case MacroscopeConstants.DocumentType.PDF: if( !MacroscopePreferencesManager.GetDataExtractorsApplyToPdf() ) { CanApply = false; } break; case MacroscopeConstants.DocumentType.TEXT: if ( !MacroscopePreferencesManager.GetDataExtractorsApplyToText() ) { CanApply = false; } break; case MacroscopeConstants.DocumentType.XML: if ( !MacroscopePreferencesManager.GetDataExtractorsApplyToXml() ) { CanApply = false; } break; default: break; } } } return ( CanApply ); }