Biblioteka sejmowa crawler
This commit is contained in:
parent
1d5b7e6b73
commit
9d298652a2
@ -4,31 +4,31 @@ import ShadowLibrary.Core
|
||||
|
||||
import Text.XML.HXT.Core
|
||||
import Text.XML.HXT.XPath
|
||||
-- import Text.XML.HXT.Curl
|
||||
import Text.XML.HXT.Curl
|
||||
import Data.List
|
||||
import Data.List.Utils (replace)
|
||||
|
||||
import Text.Regex.Posix
|
||||
import Text.Printf
|
||||
|
||||
extractAllPDFs = extractLinksWithText "/html/body/table[4]/tbody/tr[7]/td[2]/a"
|
||||
|
||||
extractRecords = extractLinksWithText "//a[@class='roczniki']" -- pary adres-tytuł
|
||||
>>> second (arr $ replace "\r\n " " ") -- czyścimy drugi element pary, czyli tytuł z niepotrzebnych białych znaków
|
||||
>>> first (arr ((++"tr") . init)) -- modyfikujemy pierwszy element pary, czyli adres URL
|
||||
>>> first (extractLinksWithText "//li/a[contains(@href,'.pdf')]") -- pobieramy stronę z adresu URL i wyciągamy linki z tej strony pasujące do wyrażenia XPathowego
|
||||
-- ostatecznie wyjdą trójki ((adres URL, tytuł artykułu), tytuł rocznika)
|
||||
extractRecords = extractLinksWithText "//table[3]//a"
|
||||
>>> first (extractLinksWithText "//table[3]//a"
|
||||
>>> first (extractLinksWithText "//table[4]//a"
|
||||
>>> first (extractAllPDFs
|
||||
>>> first(arr $ (drop 23 ) . init . init . init))))
|
||||
|
||||
-- ... a tutaj te trójki przerabiamy do docelowej struktury ShadowItem
|
||||
toShadowItem :: ((String, String), String) -> ShadowItem
|
||||
toShadowItem ((url, articleTitle), yearlyTitle) =
|
||||
toShadowItem :: ((((String, String), String), String), String) -> ShadowItem
|
||||
toShadowItem ((((url, typeName), articleTitle), _), category) =
|
||||
(defaultShadowItem url title) {
|
||||
originalDate = Just date,
|
||||
itype = "periodical",
|
||||
format = Just "pdf",
|
||||
finalUrl = url
|
||||
}
|
||||
where title = "Biblioteka Sejmowa " ++ yearlyTitle ++ " " ++ (replace "\r\n" "" (replace "\r\n " "" articleTitle))
|
||||
date = getDate url
|
||||
where title = "Biblioteka Sejmowa " ++ category ++ " " ++ typeName ++ " " ++ articleTitle
|
||||
date = getDate articleTitle
|
||||
|
||||
getDate url =
|
||||
case url =~~ "/(19[0-9][0-9]|20[0-9][0-9])/" :: Maybe [[String]] of
|
||||
@ -37,7 +37,7 @@ getDate url =
|
||||
|
||||
|
||||
main = do
|
||||
let start = "https://biblioteka.sejm.gov.pl/zasoby_cyfrowe/"
|
||||
let start = "https://bs.sejm.gov.pl/F/?con_lng=POL&func=file&file_name=find-nowe&local_base=ars01"
|
||||
let shadowLibrary = ShadowLibrary {logoUrl=Nothing,
|
||||
lname="Biblioteka Sejmowa",
|
||||
abbrev="BiblSejm",
|
||||
|
Loading…
Reference in New Issue
Block a user