Class AbstractWebDriver
-
- 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
-
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()The driver name. Function1<String, Long>getDelayPolicy()NavigateEntrygetNavigateEntry()The current navigation entry. UnitsetNavigateEntry(NavigateEntry navigateEntry)The current navigation entry. NavigateHistorygetNavigateHistory()The navigation history. BooleangetSupportJavascript()Indicates whether the driver supports javascript. BooleanisMockedPageSource()Indicate whether the page source is mocked. BooleanisRecovered()Whether the driver is recovered from the browser's tab list. UnitsetRecovered(Boolean isRecovered)Whether the driver is recovered from the browser's tab list. BooleanisReused()Whether the driver is recovered and is reused to serve new tasks. UnitsetReused(Boolean isReused)Whether the driver is recovered and is reused to serve new tasks. AtomicReference<WebDriver.State>getState()The driver status. Map<String, Object>getData()The associated data. InstantgetLastActiveTime()The time of the last action. UnitsetLastActiveTime(Instant lastActiveTime)The time of the last action. BooleanisInit()BooleanisReady()BooleanisFree()BooleanisWorking()BooleanisRetired()BooleanisQuit()BooleanisCanceled()BooleanisCrashed()StringgetSessionId()Map<String, Object>getMainRequestHeaders()List<Map<String, String>>getMainRequestCookies()IntegergetMainResponseStatus()StringgetMainResponseStatusText()Map<String, Object>getMainResponseHeaders()BrowsergetBrowser()The browser of the driver. IntegergetId()The unique driver id. 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, the other JVM languages might have difficulty to handle kotlin suspend methods. UnitnavigateTo(String url)Returns the main resource response. Stringlocation()In javascript, the window.location, ordocument.location, is a read-only property returns a Location object, which contains information about the URL of the document and provides methods for changing that URL and loading another URL.StringbaseURI()In javascript, the baseURI is a property of Node, it's the absolute base URL of the document containing the node. 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()Returns the document's HTML markup. StringouterHTML(String selector)Returns the node's HTML markup. StringfirstText(String selector)Returns the node's text content. List<String>allTexts(String selector)Returns the nodes' text contents. StringfirstAttr(String selector, String attrName)Returns the node's attribute name. List<String>allAttrs(String selector, String attrName)Returns the nodes' attribute names. 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 Jsoup session with the last page's context, which means, the same headers and cookies. ConnectionnewJsoupSession()Create a new Jsoup session with the last page's context, which means, the same headers and cookies. Connection.ResponseloadJsoupResource(String url)Load the url as a resource with Jsoup rather than browser rendering, with the last page's context, which means, the same headers and cookies. NetworkResourceResponseloadResource(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.WebDriver
addBlockedURLs, addInitScript, addProbabilityBlockedURLs, awaitTermination, boundingBox, bringToFront, captureScreenshot, captureScreenshot, clearBrowserCookies, click, clickMatches, clickablePoint, currentUrl, deleteCookies, deleteCookies, dragAndDrop, evaluate, evaluateDetail, exists, focus, getBrowserType, getCookies, isHidden, isIdle, 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.AbstractJvmWebDriver
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.JvmWebDriver
clickAsync, clickMatchesAsync -
Methods inherited from class java.io.Closeable
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
NavigateHistory getNavigateHistory()
The navigation history.
-
getSupportJavascript
Boolean getSupportJavascript()
Indicates whether the driver supports javascript. Web drivers such as MockDriver do not support javascript.
-
isMockedPageSource
Boolean isMockedPageSource()
Indicate whether the page source is mocked.
-
isRecovered
Boolean isRecovered()
Whether the driver is recovered from the browser's tab list.
-
setRecovered
Unit setRecovered(Boolean isRecovered)
Whether the driver is recovered from the browser's tab list.
-
setReused
Unit setReused(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.
-
isCanceled
Boolean isCanceled()
-
getSessionId
String getSessionId()
-
getMainRequestHeaders
Map<String, Object> getMainRequestHeaders()
-
getMainRequestCookies
List<Map<String, String>> getMainRequestCookies()
-
getMainResponseStatus
Integer getMainResponseStatus()
-
getMainResponseStatusText
String getMainResponseStatusText()
-
getMainResponseHeaders
Map<String, Object> getMainResponseHeaders()
-
getBrowser
Browser getBrowser()
The browser of the driver. The browser defines methods and events to manipulate a real browser.
-
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, the other JVM languages might have difficulty to handle 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.
-
location
String location()
In javascript, the
window.location, ordocument.location, is a read-only property returns a Location object, which contains information about the URL of the document and provides methods for changing that URL and loading another URL.To retrieve just the URL as a string, the read-only
document.URLproperty can also be used.
-
baseURI
String baseURI()
In javascript, the baseURI is a property of Node, it's the absolute base URL of the document containing the node. A baseURI is used to resolve relative URLs.
The base URL is determined as follows:
By default, the base URL is the location of the document (as determined by window.location).
If the document has an
<base>element, its href attribute is used.
-
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)
-
allAttrs
List<String> allAttrs(String selector, String attrName)
Returns the nodes' attribute names.
-
clickTextMatches
Unit clickTextMatches(String selector, String pattern, Integer count)
-
newSession
@Deprecated(message = "Inappropriate name", replaceWith = @ReplaceWith(imports = {}, expression = "newJsoupSession()")) Connection newSession()
Create a new Jsoup session with the last page's context, which means, the same headers and cookies.
-
newJsoupSession
Connection newJsoupSession()
Create a new Jsoup session with the last page's context, which means, the same headers and cookies.
-
loadJsoupResource
Connection.Response loadJsoupResource(String url)
Load the url as a resource with Jsoup rather than browser rendering, with the last page's context, which means, the same headers and cookies.
-
loadResource
NetworkResourceResponse loadResource(String url)
Load url as a resource without browser rendering, with the last page's context, which means, the same headers and cookies.
-
quit
@Deprecated(message = "Inappropriate name", replaceWith = @ReplaceWith(imports = {}, expression = "close()")) Unit quit()
Quit the browser instance
-
compareTo
Integer compareTo(AbstractWebDriver other)
-
-
-
-