shpider-0.0.1: Network/Shpider/Options.hs
-- | This module provides all the settable options in shpider.
module Network.Shpider.Options where
import Data.Maybe
import Network.Shpider.State
import Network.Shpider.URL
import Network.Shpider.TextUtils
-- | Setting this to `True` will forbid you to `download` and `sendForm` to any site which isn't on the domain shared by the url given in `setStartPage`.
stayOnDomain :: Bool -> Shpider ( )
stayOnDomain b = do
shpider <- get
put $ shpider { dontLeaveDomain =
b
}
-- | Set the start page of your shpidering antics.
-- The start page must be an absolute URL, if not, this will raise an error.
setStartPage :: String -> Shpider ( )
setStartPage uncleanUrl = do
shpider <- get
if isAbsoluteUrl url
then
put $ shpider { startPage =
url
}
else
error "The start page must be an absolute URL"
where
url =
escapeSpaces uncleanUrl
-- | Return the starting URL, as set by `setStartPage`
getStartPage :: Shpider String
getStartPage = do
shpider <- get
return $ startPage shpider
-- | If onlyDownloadHtml is True, then during `download`, shpider will make a HEAD request to see if the content type is text\/html or application\/xhtml+xml, and only if it is, then it will make a GET request.
onlyDownloadHtml :: Bool -> Shpider ( )
onlyDownloadHtml b = do
st <- get
put $ st { htmlOnlyDownloads = b }
-- | Set the given page as the `currentPage`.
setCurrentPage :: Page -> Shpider ( )
setCurrentPage p = do
shpider <- get
put $ shpider { currentPage = p }
-- | Return the current page
getCurrentPage :: Shpider Page
getCurrentPage = do
sh <- get
return $ currentPage sh
-- | When keepTrack is set, shpider will remember the pages which have been `visited`.
keepTrack :: Shpider ( )
keepTrack = do
shpider <- get
put $ shpider { visited = Just [ ] }