-
- All Implemented Interfaces:
-
ai.platon.pulsar.crawl.fetch.driver.JvmWebDriver,ai.platon.pulsar.crawl.fetch.driver.WebDriver,java.io.Closeable,java.lang.AutoCloseable,kotlin.Comparable
public abstract class AbstractWebDriver extends AbstractJvmWebDriver implements Comparable<AbstractWebDriver>, WebDriver, JvmWebDriver
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classAbstractWebDriver.Companion
-
Field Summary
Fields Modifier and Type Field Description private DurationidleTimeoutprivate DurationwaitForElementTimeoutprivate final Stringnameprivate final Function1<String, Long>delayPolicyprivate NavigateEntrynavigateEntryprivate final List<NavigateEntry>navigateHistoryprivate final BooleansupportJavascriptprivate final BooleanisMockedPageSourceprivate BooleanisRecoveredprivate BooleanisReusedprivate final AtomicReference<WebDriver.State>stateprivate InstantlastActiveTimeprivate final BooleanisInitprivate final BooleanisReadyprivate final BooleanisFreeprivate final BooleanisWorkingprivate final BooleanisRetiredprivate final BooleanisQuitprivate final BooleanisCanceledprivate final BooleanisCrashedprivate final StringsessionIdprivate final Browserbrowserprivate final Integeridprivate final BrowserTypebrowserTypeprivate final BooleanisIdle
-
Constructor Summary
Constructors Constructor Description AbstractWebDriver(Browser browser, Integer id)
-
Method Summary
Modifier and Type Method Description DurationgetIdleTimeout()The idle timeout. UnitsetIdleTimeout(Duration idleTimeout)The idle timeout. DurationgetWaitForElementTimeout()The timeout to wait for some object. UnitsetWaitForElementTimeout(Duration waitForElementTimeout)The timeout to wait for some object. StringgetName()Function1<String, Long>getDelayPolicy()NavigateEntrygetNavigateEntry()The current navigation entry. UnitsetNavigateEntry(NavigateEntry navigateEntry)The current navigation entry. List<NavigateEntry>getNavigateHistory()The navigation history. BooleangetSupportJavascript()Indicates whether the driver supports javascript. BooleangetIsMockedPageSource()Indicate whether the page source is mocked. BooleangetIsRecovered()Whether the driver is recovered from the browser's tab list. UnitsetIsRecovered(Boolean isRecovered)Whether the driver is recovered from the browser's tab list. BooleangetIsReused()Whether the driver is recovered and is reused to serve new tasks. UnitsetIsReused(Boolean isReused)Whether the driver is recovered and is reused to serve new tasks. AtomicReference<WebDriver.State>getState()The driver status. InstantgetLastActiveTime()The time of the last action. UnitsetLastActiveTime(Instant lastActiveTime)The time of the last action. BooleangetIsInit()BooleangetIsReady()BooleangetIsFree()BooleangetIsWorking()BooleangetIsRetired()BooleangetIsQuit()BooleangetIsCanceled()BooleangetIsCrashed()StringgetSessionId()BrowsergetBrowser()The browser of the driver. IntegergetId()The unique driver id. abstract BrowserTypegetBrowserType()The browser type. BooleangetIsIdle()Unitfree()Mark the driver as free, so it can be used to fetch a new page. UnitstartWork()Mark the driver as working, so it can not be used to fetch another page. Unitretire()Mark the driver as retired, so it can not be used to fetch any page, and should be quit as soon as possible. Unitcancel()Mark the driver as canceled, so the fetch process should return as soon as possible, and the fetch result should be dropped. JvmWebDriverjvm()Returns a JvmWebDriver to support other JVM languages, such as java, clojure, scala, and so on, which had difficulty handling kotlin suspend methods. UnitnavigateTo(String url)Returns the main resource response. LongwaitForSelector(String selector, Long timeoutMillis)Returns when element specified by selector satisfies {@code state} option. LongwaitForSelector(String selector)Returns when element specified by selector satisfies {@code state} option. LongwaitForNavigation()LongwaitForNavigation(Long timeoutMillis)ObjectevaluateSilently(String expression)Executes JavaScript in the context of the currently selected frame or window. BooleanisVisible(String selector)BooleanisChecked(String selector)UnitscrollDown(Integer count)UnitscrollUp(Integer count)UnitscrollToTop()UnitscrollToBottom()UnitscrollToMiddle(Float ratio)StringclickNthAnchor(Integer n, String rootSelector)StringouterHTML(String selector)StringfirstText(String selector)List<String>allTexts(String selector)StringfirstAttr(String selector, String attrName)List<String>allAttrs(String selector, String attrName)UnitclickTextMatches(String selector, String pattern, Integer count)UnitclickMatches(String selector, String attrName, String pattern, Integer count)Unitcheck(String selector)Unituncheck(String selector)ConnectionnewSession()Create a new session with the same context of the browser: headers, cookies, proxy, etc. Connection.ResponseloadResource(String url)Load url as a resource without browser rendering, with the last page's context, which means, the same headers and cookies. Unitquit()Quit the browser instance Booleanequals(Object other)IntegerhashCode()IntegercompareTo(AbstractWebDriver other)StringtoString()-
Methods inherited from class ai.platon.pulsar.crawl.fetch.driver.AbstractJvmWebDriver
addBlockedURLs, addInitScript, addProbabilityBlockedURLs, awaitTermination, boundingBox, bringToFront, captureScreenshot, captureScreenshot, click, clickAsync, clickMatches, clickMatchesAsync, clickablePoint, currentUrl, dragAndDrop, evaluate, evaluateDetail, exists, focus, getCookies, isHidden, mainRequestCookies, mainRequestHeaders, mouseWheelDown, mouseWheelUp, moveMouseTo, moveMouseTo, navigateTo, pageSource, pause, scrollTo, setTimeouts, stop, stopLoading, terminate, type, visible, waitForNavigation, waitForPage, waitForSelector -
Methods inherited from class ai.platon.pulsar.crawl.fetch.driver.AbstractWebDriver
addBlockedURLsAsync, addInitScriptAsync, allAttrsAsync, allTextsAsync, boundingBoxAsync, bringToFrontAsync, captureScreenshotAsync, captureScreenshotAsync, checkAsync, clickAsync, clickMatchesAsync, clickMatchesAsync, clickNthAnchorAsync, clickablePointAsync, currentUrlAsync, dragAndDropAsync, evaluateAsync, evaluateSilentlyAsync, existsAsync, firstAttrAsync, firstTextAsync, getCookiesAsync, isCheckedAsync, isHiddenAsync, isVisibleAsync, loadResourceAsync, mainRequestCookiesAsync, mainRequestHeadersAsync, mouseWheelDownAsync, mouseWheelUpAsync, moveMouseToAsync, navigateToAsync, navigateToAsync, newSessionAsync, outerHTMLAsync, pageSourceAsync, pauseAsync, scrollDownAsync, scrollToAsync, scrollToBottomAsync, scrollToMiddleAsync, scrollToTopAsync, scrollUpAsync, setTimeoutsAsync, stopAsync, terminateAsync, typeAsync, uncheckAsync, visibleAsync, waitForNavigationAsync, waitForNavigationAsync, waitForNavigationAsync, waitForSelectorAsync, waitForSelectorAsync, waitForSelectorAsync -
Methods inherited from class ai.platon.pulsar.crawl.fetch.driver.WebDriver
close -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getIdleTimeout
Duration getIdleTimeout()
The idle timeout.
-
setIdleTimeout
Unit setIdleTimeout(Duration idleTimeout)
The idle timeout.
-
getWaitForElementTimeout
Duration getWaitForElementTimeout()
The timeout to wait for some object.
-
setWaitForElementTimeout
Unit setWaitForElementTimeout(Duration waitForElementTimeout)
The timeout to wait for some object.
-
getDelayPolicy
Function1<String, Long> getDelayPolicy()
-
getNavigateEntry
NavigateEntry getNavigateEntry()
The current navigation entry.
-
setNavigateEntry
Unit setNavigateEntry(NavigateEntry navigateEntry)
The current navigation entry.
-
getNavigateHistory
List<NavigateEntry> getNavigateHistory()
The navigation history.
-
getSupportJavascript
Boolean getSupportJavascript()
Indicates whether the driver supports javascript. Web drivers such as MockDriver do not support javascript.
-
getIsMockedPageSource
Boolean getIsMockedPageSource()
Indicate whether the page source is mocked.
-
getIsRecovered
Boolean getIsRecovered()
Whether the driver is recovered from the browser's tab list.
-
setIsRecovered
Unit setIsRecovered(Boolean isRecovered)
Whether the driver is recovered from the browser's tab list.
-
getIsReused
Boolean getIsReused()
Whether the driver is recovered and is reused to serve new tasks.
-
setIsReused
Unit setIsReused(Boolean isReused)
Whether the driver is recovered and is reused to serve new tasks.
-
getState
AtomicReference<WebDriver.State> getState()
The driver status.
-
getLastActiveTime
Instant getLastActiveTime()
The time of the last action.
-
setLastActiveTime
Unit setLastActiveTime(Instant lastActiveTime)
The time of the last action.
-
getIsReady
Boolean getIsReady()
-
getIsWorking
Boolean getIsWorking()
-
getIsRetired
Boolean getIsRetired()
-
getIsCanceled
Boolean getIsCanceled()
-
getIsCrashed
Boolean getIsCrashed()
-
getSessionId
String getSessionId()
-
getBrowser
Browser getBrowser()
The browser of the driver. The browser defines methods and events to manipulate a real browser.
-
getBrowserType
abstract BrowserType getBrowserType()
The browser type.
-
retire
Unit retire()
Mark the driver as retired, so it can not be used to fetch any page, and should be quit as soon as possible.
-
cancel
Unit cancel()
Mark the driver as canceled, so the fetch process should return as soon as possible, and the fetch result should be dropped.
-
jvm
JvmWebDriver jvm()
Returns a JvmWebDriver to support other JVM languages, such as java, clojure, scala, and so on, which had difficulty handling kotlin suspend methods.
-
navigateTo
Unit navigateTo(String url)
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first non-redirect response.
- Parameters:
url- URL to navigate page to.
-
waitForSelector
Long waitForSelector(String selector, Long timeoutMillis)
Returns when element specified by selector satisfies {@code state} option. Returns the time remaining until timeout.
-
waitForSelector
Long waitForSelector(String selector)
Returns when element specified by selector satisfies {@code state} option.
-
waitForNavigation
Long waitForNavigation()
-
waitForNavigation
Long waitForNavigation(Long timeoutMillis)
-
evaluateSilently
Object evaluateSilently(String expression)
Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.
All possible exceptions are suppressed and do not throw.
- Parameters:
expression- Javascript expression to evaluate
-
scrollDown
Unit scrollDown(Integer count)
-
scrollToTop
Unit scrollToTop()
-
scrollToBottom
Unit scrollToBottom()
-
scrollToMiddle
Unit scrollToMiddle(Float ratio)
-
clickNthAnchor
String clickNthAnchor(Integer n, String rootSelector)
-
clickTextMatches
Unit clickTextMatches(String selector, String pattern, Integer count)
-
newSession
Connection newSession()
Create a new session with the same context of the browser: headers, cookies, proxy, etc. The browser should be initialized by opening a page before the session is created.
-
loadResource
Connection.Response loadResource(String url)
Load url as a resource without browser rendering, with the last page's context, which means, the same headers and cookies.
-
compareTo
Integer compareTo(AbstractWebDriver other)
-
-
-
-