Class LoadOptions

  • All Implemented Interfaces:
    ai.platon.pulsar.common.config.Parameterized

    
    public class LoadOptions
    extends CommonOptions
                        

    A LoadOptions object contains a set of control parameters that affect how we load a webpage.

    The load options, or load arguments, can be a plain string in the form of command line parameters, and can be parsed into a LoadOptions object.

    // parse a string into a LoadOptions object
    val options = session.options('-expires 1d -itemExpires 1d -ignoreFailure -parse -storeContent')
    // fetch after 1d since last fetch
    session.load('https://www.jd.com', '-expires 1d')
    // fetch immediately ignoring errors
    session.load('https://www.jd.com', '-refresh')
    // do not fetch after dead time
    session.load('https://www.jd.com', '-deadline 2022-04-15T18:36:54.941Z')
    // activate the parse phase
    session.load('https://www.jd.com', '-parse')
    // write the page content into storage
    session.load('https://www.jd.com', '-storeContent')

    TODO: support new options: -priority TODO: keep unsupported options

    • Method Detail

      • getEntity

         final String getEntity()

        The entity name of the page, for example, article, product, hotel, flower, etc, it's optional.

      • setEntity

         final Unit setEntity(String entity)

        The entity name of the page, for example, article, product, hotel, flower, etc, it's optional.

      • getLabel

         final String getLabel()

        The task label, it's optional and can be used to group tasks.

      • setLabel

         final Unit setLabel(String label)

        The task label, it's optional and can be used to group tasks.

      • getTaskId

         final String getTaskId()

        The task id, it's optional and can be used to distinguish tasks.

      • setTaskId

         final Unit setTaskId(String taskId)

        The task id, it's optional and can be used to distinguish tasks.

      • getTaskTime

         final Instant getTaskTime()

        The task time, we usually use task time to indicate the name of a task batch.

      • setTaskTime

         final Unit setTaskTime(Instant taskTime)

        The task time, we usually use task time to indicate the name of a task batch.

      • getDeadline

         final Instant getDeadline()

        The deadline to finish the task, if the deadline is exceeded, the task should be discarded as soon as possible.

        :::

        NOTICE: The arguments "-deadTime", "--dead-time" are deprecated, will be removed in the further.

        :::

      • setDeadline

         final Unit setDeadline(Instant deadline)

        The deadline to finish the task, if the deadline is exceeded, the task should be discarded as soon as possible.

        :::

        NOTICE: The arguments "-deadTime", "--dead-time" are deprecated, will be removed in the further.

        :::

      • getAuthToken

         final String getAuthToken()

        The auth token, used for authorization purpose.

      • getReadonly

         final Boolean getReadonly()

        Specify if the load execution is read only or not. If a load execution is read only, the webpage loaded should not be changed by the execution.

      • setReadonly

         final Unit setReadonly(Boolean readonly)

        Specify if the load execution is read only or not. If a load execution is read only, the webpage loaded should not be changed by the execution.

      • isResource

         final Boolean isResource()

        If true, fetch the url as a resource without browser rendering.

      • setResource

         final Unit setResource(Boolean isResource)

        If true, fetch the url as a resource without browser rendering.

      • getExpires

         final Duration getExpires()

        The expiry duration. If the expiry time is exceeded, the page should be fetched from the Internet.

        The term "expires" usually be used for an expiry time, for example, http-equiv, or in cookie specification, guess it means "expires at".

        The expires field supports both ISO-8601 standard and hadoop time duration format:

        • ISO-8601 standard : PnDTnHnMn.nS

        • Hadoop time duration format: 100s, 1m, 1h, 1d, valid units are : ns, us, ms, s, m, h, d.

      • setExpires

         final Unit setExpires(Duration expires)

        The expiry duration. If the expiry time is exceeded, the page should be fetched from the Internet.

        The term "expires" usually be used for an expiry time, for example, http-equiv, or in cookie specification, guess it means "expires at".

        The expires field supports both ISO-8601 standard and hadoop time duration format:

        • ISO-8601 standard : PnDTnHnMn.nS

        • Hadoop time duration format: 100s, 1m, 1h, 1d, valid units are : ns, us, ms, s, m, h, d.

      • getExpireAt

         final Instant getExpireAt()

        The expiry time point. If the expiry time is exceeded, the page should be fetched from the Internet.

        Accept the following format:

        • yyyy-MM-dd[ HH[:mm:ss]]

        • ISO_INSTANT, or yyyy-MM-ddTHH:mm:ssZ

      • setExpireAt

         final Unit setExpireAt(Instant expireAt)

        The expiry time point. If the expiry time is exceeded, the page should be fetched from the Internet.

        Accept the following format:

        • yyyy-MM-dd[ HH[:mm:ss]]

        • ISO_INSTANT, or yyyy-MM-ddTHH:mm:ssZ

      • getClickTarget

         final String getClickTarget()

        The selector for element to click. TODO: not implemented yet

      • setClickTarget

         final Unit setClickTarget(String clickTarget)

        The selector for element to click. TODO: not implemented yet

      • getIframe

         final Integer getIframe()

        The iframe id to switch to. TODO: not implemented yet

      • setIframe

         final Unit setIframe(Integer iframe)

        The iframe id to switch to. TODO: not implemented yet

      • getTopLinks

         final Integer getTopLinks()

        Specify how many links to extract for out pages.

      • getTopNAnchorGroups

         final Integer getTopNAnchorGroups()

        Choose the top N anchor groups for further process. Used by auto web mining project.

      • setTopNAnchorGroups

         final Unit setTopNAnchorGroups(Integer topNAnchorGroups)

        Choose the top N anchor groups for further process. Used by auto web mining project.

      • getWaitNonBlank

         final String getWaitNonBlank()

        The selector specified element should have a non-blank text, the system should wait until the element is filled by a non-blank text, or until it times out. TODO: not implemented yet

      • setWaitNonBlank

         final Unit setWaitNonBlank(String waitNonBlank)

        The selector specified element should have a non-blank text, the system should wait until the element is filled by a non-blank text, or until it times out. TODO: not implemented yet

      • getRequireNotBlank

         final String getRequireNotBlank()

        The selector specified element should have a non-blank text, the task should be retried if the element's text content is empty or blank. TODO: not implemented yet

      • setRequireNotBlank

         final Unit setRequireNotBlank(String requireNotBlank)

        The selector specified element should have a non-blank text, the task should be retried if the element's text content is empty or blank. TODO: not implemented yet

      • getRequireSize

         final Integer getRequireSize()

        The minimum page size expected, if it is less than that, it will need to be re-fetched.

        The unit is byte.

      • setRequireSize

         final Unit setRequireSize(Integer requireSize)

        The minimum page size expected, if it is less than that, it will need to be re-fetched.

        The unit is byte.

      • getRequireImages

         final Integer getRequireImages()

        The minimum number of images expected in the page, if it is less than that, it will need to be re-fetched.

      • setRequireImages

         final Unit setRequireImages(Integer requireImages)

        The minimum number of images expected in the page, if it is less than that, it will need to be re-fetched.

      • getRequireAnchors

         final Integer getRequireAnchors()

        The minimum number of anchors expected in the page, if it is less than that, it will need to be re-fetched.

      • setRequireAnchors

         final Unit setRequireAnchors(Integer requireAnchors)

        The minimum number of anchors expected in the page, if it is less than that, it will need to be re-fetched.

      • getFetchMode

         final FetchMode getFetchMode()

        The fetch mode.

        Only BROWSER is supported currently.

      • setFetchMode

         final Unit setFetchMode(FetchMode fetchMode)

        The fetch mode.

        Only BROWSER is supported currently.

      • getBrowser

         final BrowserType getBrowser()

        Specify which browser to use, google chrome is the default. TODO: session scope browser choice is not support by now

      • setBrowser

         final Unit setBrowser(BrowserType browser)

        Specify which browser to use, google chrome is the default. TODO: session scope browser choice is not support by now

      • getScrollCount

         final Integer getScrollCount()

        The number of times the page should be scrolled down after it has just been opened in a browser.

      • setScrollCount

         final Unit setScrollCount(Integer scrollCount)

        The number of times the page should be scrolled down after it has just been opened in a browser.

      • getItemBrowser

         final BrowserType getItemBrowser()

        The browser used to visit the item pages. TODO: session scope browser choice is not support by now

      • setItemBrowser

         final Unit setItemBrowser(BrowserType itemBrowser)

        The browser used to visit the item pages. TODO: session scope browser choice is not support by now

      • getItemExpireAt

         final Instant getItemExpireAt()

        If an item page is expired, it should be fetched from the web again.

      • setItemExpireAt

         final Unit setItemExpireAt(Instant itemExpireAt)

        If an item page is expired, it should be fetched from the web again.

      • getStoreContent

         final Boolean getStoreContent()

        If false, do not persist the page content which is usually very large.

      • setStoreContent

         final Unit setStoreContent(Boolean storeContent)

        If false, do not persist the page content which is usually very large.

      • getDropContent

         final Boolean getDropContent()

        If the option is set, do not persist the page content which is usually very large. If the option is set, it overrides storeContent.

      • setDropContent

         final Unit setDropContent(Boolean dropContent)

        If the option is set, do not persist the page content which is usually very large. If the option is set, it overrides storeContent.

      • getRefresh

         final Boolean getRefresh()

        Refresh the fetch state of a page, clear the retry counters. If true, the page should be fetched, just like we click the refresh button on a real browser. The option can be explained as follows: -refresh = -ignoreFailure -i 0s and set page.fetchRetries = 0.

        TODO: consider add an option itemRefresh

      • getNMaxRetry

         final Integer getNMaxRetry()

        Retry to fetch at most n times, if page.fetchRetries nMaxRetry, the page is marked as gone and do not fetch it again until -refresh is set to clear page.fetchRetries

      • setNMaxRetry

         final Unit setNMaxRetry(Integer nMaxRetry)

        Retry to fetch at most n times, if page.fetchRetries nMaxRetry, the page is marked as gone and do not fetch it again until -refresh is set to clear page.fetchRetries

      • getNJitRetry

         final Integer getNJitRetry()

        Retry at most n times at fetch phase immediately if RETRY(1601) code return.

      • setNJitRetry

         final Unit setNJitRetry(Integer nJitRetry)

        Retry at most n times at fetch phase immediately if RETRY(1601) code return.

      • getLazyFlush

         final Boolean getLazyFlush()

        If false, pages are flushed into database as soon as possible.

      • setLazyFlush

         final Unit setLazyFlush(Boolean lazyFlush)

        If false, pages are flushed into database as soon as possible.

      • getIncognito

         final Boolean getIncognito()

        Run browser in incognito mode. Not used since the browser always running in temporary contexts.

      • setIncognito

         final Unit setIncognito(Boolean incognito)

        Run browser in incognito mode. Not used since the browser always running in temporary contexts.

      • getNoRedirect

         final Boolean getNoRedirect()

        Do not redirect. Ignored in browser mode since the browser handles the redirection itself.

      • setNoRedirect

         final Unit setNoRedirect(Boolean noRedirect)

        Do not redirect. Ignored in browser mode since the browser handles the redirection itself.

      • getHardRedirect

         final Boolean getHardRedirect()

        If false, return the original page record but the redirect target's content, otherwise, return the page record of the redirected target. If we use a browser, redirections are handled by the browser so the flag is ignored.

      • setHardRedirect

         final Unit setHardRedirect(Boolean hardRedirect)

        If false, return the original page record but the redirect target's content, otherwise, return the page record of the redirected target. If we use a browser, redirections are handled by the browser so the flag is ignored.

      • getParse

         final Boolean getParse()

        If true, parse the page when it's just be fetched.

      • setParse

         final Unit setParse(Boolean parse)

        If true, parse the page when it's just be fetched.

      • getNoNorm

         final Boolean getNoNorm()

        If true, no normalizer will be applied when parse links.

      • setNoNorm

         final Unit setNoNorm(Boolean noNorm)

        If true, no normalizer will be applied when parse links.

      • getNoFilter

         final Boolean getNoFilter()

        If true, no filter will be applied when parse links.

      • getTest

         final Integer getTest()

        The test level, 0 to disable, we will talk more in test mode.

      • setTest

         final Unit setTest(Integer test)

        The test level, 0 to disable, we will talk more in test mode.

      • getConf

         final VolatileConfig getConf()
      • isDead

         final Boolean isDead()

        If the page is dead, drop the task as soon as possible.

      • itemOptions2MajorOptions

         Unit itemOptions2MajorOptions()

        Convert the item options to major options. The system do not use item options directly, we have to do the convert before we process item pages.

      • overrideConfiguration

         final VolatileConfig overrideConfiguration()

        Write option values to conf.

        LoadOptions is not globally visible, we have to pass values to modules which can not see it through a VolatileConfig object.

      • overrideConfiguration

         final VolatileConfig overrideConfiguration(VolatileConfig conf)

        Write option values to conf.

        LoadOptions is not globally visible, we have to pass values to modules which can not see it through a VolatileConfig object.

      • toString

         String toString()

        Convert the LoadOptions to a string. The two operations parse and toString are reversible:

        val args = "..."
        val options1 = LoadOptions.parse(args)
        val normalizedArgs = options1
        val options2 = LoadOptions.parse(normalizedArgs)
        require(normalizedArgs == options2.toString())