Wikipedia fornisce un link (lato sinistro su Stampa/esportazione) su ogni articolo per scaricare l'articolo in formato pdf. Ho scritto un piccolo script Haskell che prima ottiene il link di Wikipedia e mostra il link di rendering. Quando sto dando l'url di rendering come input, ricevo tag vuoti ma lo stesso URL nel browser fornisce il link per il download.Scarica il file pdf da wikipedia
Qualcuno potrebbe dirmi come risolvere questo problema? Codice formattato su ideone.
import Network.HTTP
import Text.HTML.TagSoup
import Data.Maybe
parseHelp :: Tag String -> Maybe String
parseHelp (TagOpen _ y) = if any (\(a , b) -> b == "Download a PDF version of this wiki page") y
then Just $ "http://en.wikipedia.org" ++ snd ( y !! 0)
else Nothing
parse :: [ Tag String ] -> Maybe String
parse [] = Nothing
parse (x : xs)
| isTagOpen x = case parseHelp x of
Just s -> Just s
Nothing -> parse xs
| otherwise = parse xs
main = do
x <- getLine
tags_1 <- fmap parseTags $ getResponseBody =<< simpleHTTP (getRequest x) --open url
let lst = head . sections (~== "<div class=portal id=p-coll-print_export>") $ tags_1
url = fromJust . parse $ lst --rendering url
putStrLn url
tags_2 <- fmap parseTags $ getResponseBody =<< simpleHTTP (getRequest url)
print tags_2
Per coloro che desiderano scaricare direttamente in pdf e non so come fare, consulta http: // www.youtube.com/watch?v=juBDM3fb-i0 –