From cb5948925da9de861c72dfb45babcdf40d7701fc Mon Sep 17 00:00:00 2001 From: Norbert Litkowski Date: Wed, 7 Apr 2021 03:54:56 +0200 Subject: [PATCH] Fetching text --- app/ZborBielawa.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/ZborBielawa.hs b/app/ZborBielawa.hs index 0113d9b..2dd6c11 100644 --- a/app/ZborBielawa.hs +++ b/app/ZborBielawa.hs @@ -4,21 +4,20 @@ import ShadowLibrary.Core import Text.XML.HXT.Core import Text.XML.HXT.XPath --- import Text.XML.HXT.Curl + import Data.List import Data.List.Utils (replace) import Text.Regex.Posix import Text.Printf -import Debug.Trace getLinkAndText xpathCondition = proc doc -> do xpathTrees <- getXPathTrees xpathCondition -< doc name <- getElemName -< xpathTrees - txt <- (getXPathTrees "../text()" >>> getText) -< xpathTrees + txt <- (listA (deep isText >>> getText) >>> arr (intercalate " ")) -< xpathTrees href <- (getXPathTrees "//a" >>> getAttrValue "href") -< xpathTrees - returnA -< trace ("AAAAAAAAAAAAAAAA " ++ show name) $ traceShowId (href, txt) + returnA -< href, txt extractNestedLinksWithText xpathCondition = proc url -> do @@ -31,7 +30,7 @@ extractNestedLinksWithText xpathCondition = proc url -> do extractRecords = proc x -> do (a, b) <- extractLinksWithText "(//aside[@class='widget widget_maxmegamenu']//a[@class='mega-menu-link'])[1]" -< x -- pary adres-tytuł podstrony (a', b') <- (extractLinksWithText "(//aside[@class='widget widget_maxmegamenu']//a[@class='mega-menu-link'])[1]") -< a -- pobieramy podstronę i kolejne podstrony z menu - a'' <- (extractNestedLinksWithText "//big/a[contains(@href,'.pdf')][img]") -< a' -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego + a'' <- (extractNestedLinksWithText "//big[a[contains(@href,'.pdf')][img]]") -< a' -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego returnA -< ((a'', b'), b) -- ostatecznie wyjdą krotki (((adres URL, tytuł nr-u), tytuł podstrony 2), tytuł podstrony 1)