-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public interface PulsarSession implements AutoCloseable
PulsarSession defines a concise interface to fetch webpages, from the local storage or the Internet, and methods to parse, extract, persist, index, export them.
Key methods:
PulsarSession.load, load a webpage from local storage, or fetch it from the Internet. PulsarSession.parse, parse a webpage into a document. PulsarSession.scrape, load a webpage, parse it into a document and then extract fields from the document.
And also the batch versions:
PulsarSession.loadOutPages, load the portal page and out pages. PulsarSession.scrapeOutPages, load the portal page and out pages, extract fields from out pages.
The first method to keep in mind is how to load a page.
A load method checks the local storage first, if it exists and is good, return the persisted version, otherwise, fetch it from the Internet.
Other fetch condition can be specified in load arguments, or load options:
expiration
page size requirements
field requirements
Once a webpage is loaded from local storage, or fetched from the Internet, we come to the next process steps:
parse the web content into a HTML document
extract fields from the HTML document
write the fields into a destination, such as
There are many ways to fetch the content of a page from the Internet:
http protocol
through a real browser
Since the webpages are becoming more and more complex, fetching webpages through real browsers is the primer way nowadays.
When we fetch webpages using a real browser, we may need to interact with pages to ensure the desired fields are loaded correctly and completely. Activate PageEvent and use WebDriver to archive such purpose.
val options = session.options(args) options.event.simulateEvent.onDidDOMStateCheck.addLast { page, driver -> driver.scrollDown() } session.load(url, options)Pulsar WebDriver provides a complete method set for RPA, just like selenium, playwright and puppeteer, all actions and behaviors are optimized to mimic real people as closely as possible.
-
-
Method Summary
Modifier and Type Method Description abstract BooleanregisterClosable(AutoCloseable closable)Close objects when the session closes abstract UnitdisablePDCache()Disable page cache and document cache abstract LoadOptionsoptions(String args, PageEvent event)Create a new options, with a new volatile config abstract Stringproperty(String name)Get a property abstract Unitproperty(String name, String value)Set a session scope property abstract NormUrlnormalize(String url, String args)Normalize a url abstract NormUrlnormalize(String url, LoadOptions options, Boolean toItemOption)Normalize a url abstract List<NormUrl>normalize(Iterable<String> urls, LoadOptions options, Boolean toItemOption)Normalize urls abstract NormUrlnormalize(UrlAware url, LoadOptions options, Boolean toItemOption)Normalize a url abstract List<NormUrl>normalize(Collection<UrlAware> urls, LoadOptions options, Boolean toItemOption)Normalize urls abstract NormUrlnormalizeOrNull(String url, LoadOptions options, Boolean toItemOption)Normalize a url abstract NormUrlnormalizeOrNull(UrlAware url, LoadOptions options, Boolean toItemOption)Normalize a url abstract WebPageinject(String url)Inject a url to fetch later abstract WebPageget(String url)Get a page from database if exists abstract WebPagegetOrNull(String url)Get a page from database if exists abstract Booleanexists(String url)Check if a page exists in the database abstract CheckStatefetchState(WebPage page, LoadOptions options)Return the fetch state of the page abstract WebPageopen(String url)Open a url. abstract WebPageload(String url, String args)Load a url with arguments. abstract WebPageload(String url, LoadOptions options)Load a url with options. abstract WebPageload(UrlAware url, String args)Load a url with specified options abstract WebPageload(UrlAware url, LoadOptions options)Load a url with options. abstract WebPageload(NormUrl normUrl)Load a url in normalized form. abstract WebPageloadDeferred(String url, LoadOptions options)Load a url with specified options. abstract WebPageloadDeferred(UrlAware url, String args)Load a url with specified options. abstract WebPageloadDeferred(UrlAware url, LoadOptions options)Load a url with specified options. abstract WebPageloadDeferred(NormUrl normUrl)Load a url with specified optionsThis function is a kotlin suspend function, which could be started, paused, and resume. abstract List<WebPage>loadAll(Iterable<String> urls, LoadOptions options)Load all urls with specified options, this causes a parallel fetching whenever applicable abstract List<WebPage>loadAll(Iterable<NormUrl> normUrls)Load all urls with specified options abstract CompletableFuture<WebPage>loadAsync(NormUrl url)Load a url with java async style abstract List<CompletableFuture<WebPage>>loadAllAsync(Iterable<NormUrl> urls)Load all urls with specified options with java async style abstract PulsarSessionsubmit(UrlAware url)Submit a url to the url pool, the url will be processed in the main crawl loop later abstract PulsarSessionsubmitAll(Iterable<UrlAware> urls)Submit the urls to the url pool, the submitted urls will be processed in the main crawl loop later abstract List<WebPage>loadOutPages(String portalUrl, String args)Load out pages linked from the portal page abstract List<WebPage>loadOutPages(String portalUrl, LoadOptions options)Load out pages linked from the portal page abstract List<CompletableFuture<WebPage>>loadOutPagesAsync(String portalUrl, LoadOptions options)Load out pages linked from the portal page abstract AbstractPulsarSessionsubmitOutPages(String portalUrl, String args)Submit the urls of out pages in the portal page, the submitted urls will be processed in the main crawl loop later abstract PulsarSessionsubmitOutPages(String portalUrl, LoadOptions options)Submit the urls of out pages in the portal page, the submitted urls will be processed in the main crawl loop later abstract WebPageloadResource(String url, String referer, String args)Load a url as a resource without browser rendering in the browser contextThis function is a kotlin suspend function, which could be started, paused, and resume. abstract WebPageloadResource(String url, String referer, LoadOptions opts)Load a url as a resource without browser rendering in the browser contextThis function is a kotlin suspend function, which could be started, paused, and resume. abstract FeaturedDocumentparse(WebPage page, Boolean noCache)Parse the Web page into DOM. abstract FeaturedDocumentloadDocument(String url, String args)Load or fetch a webpage and parse it into a document abstract FeaturedDocumentloadDocument(String url, LoadOptions options)Load or fetch a webpage and parse it into a document abstract FeaturedDocumentloadDocument(NormUrl normUrl)Load or fetch a webpage and parse it into a document abstract Map<String, String>scrape(String url, String args, Iterable<String> fieldSelectors)Scrape a webpage abstract Map<String, String>scrape(String url, LoadOptions options, Iterable<String> fieldSelectors)Scrape a webpage abstract Map<String, String>scrape(String url, String args, Map<String, String> fieldSelectors)Scrape a webpage abstract Map<String, String>scrape(String url, LoadOptions options, Map<String, String> fieldSelectors)Scrape a webpage abstract List<Map<String, String>>scrape(String url, String args, String restrictSelector, Iterable<String> fieldSelectors)Scrape a webpage abstract List<Map<String, String>>scrape(String url, LoadOptions options, String restrictSelector, Iterable<String> fieldSelectors)Scrape a webpage abstract List<Map<String, String>>scrape(String url, String args, String restrictSelector, Map<String, String> fieldSelectors)Scrape a webpage abstract List<Map<String, String>>scrape(String url, LoadOptions options, String restrictSelector, Map<String, String> fieldSelectors)Scrape a webpage abstract List<Map<String, String>>scrapeOutPages(String portalUrl, String args, Iterable<String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, LoadOptions options, Iterable<String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, String args, String restrictSelector, Iterable<String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, LoadOptions options, String restrictSelector, Iterable<String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, String args, Map<String, String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, LoadOptions options, Map<String, String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, String args, String restrictSelector, Map<String, String> fieldSelectors)Scrape out pages using given selectors. abstract List<Map<String, String>>scrapeOutPages(String portalUrl, LoadOptions options, String restrictSelector, Map<String, String> fieldSelectors)Scrape out pages using given selectors. abstract ObjectgetVariable(String name)Get a variable associated with this session abstract UnitsetVariable(String name, Object value)Set a variable associated with this session abstract UnitputSessionBean(Object obj)Put session scope bean abstract Unitdelete(String url)Delete a webpage from the backend storage abstract Unitflush()Flush to the storage abstract Booleanpersist(WebPage page)Persist to the storage abstract Pathexport(WebPage page, String ident)Export the content of a webpage. abstract Pathexport(FeaturedDocument doc, String ident)Export the outer HTML of the document. abstract PathexportTo(FeaturedDocument doc, Path path)Export the whole HTML of the document to the given path. abstract IntegergetId()The session id. abstract PulsarContextgetContext()The pulsar context abstract VolatileConfiggetSessionConfig()The session scope volatile config, every setting is supposed to be changed at any time and any place abstract ImmutableConfiggetUnmodifiedConfig()abstract BeanFactorygetSessionBeanFactory()The scoped bean factory: for each volatileConfig object, there is a bean factory abstract StringgetDisplay()A short descriptive display text. abstract ConcurrentExpiringLRUCache<String, WebPage>getPageCache()The global page cache abstract ConcurrentExpiringLRUCache<String, FeaturedDocument>getDocumentCache()The global document cache abstract GlobalCachegetGlobalCache()The global cache abstract GlobalCacheFactorygetGlobalCacheFactory()-
-
Method Detail
-
registerClosable
abstract Boolean registerClosable(AutoCloseable closable)
Close objects when the session closes
-
disablePDCache
abstract Unit disablePDCache()
Disable page cache and document cache
-
options
abstract LoadOptions options(String args, PageEvent event)
Create a new options, with a new volatile config
-
normalize
abstract NormUrl normalize(String url, LoadOptions options, Boolean toItemOption)
Normalize a url
-
normalize
abstract List<NormUrl> normalize(Iterable<String> urls, LoadOptions options, Boolean toItemOption)
Normalize urls
-
normalize
abstract NormUrl normalize(UrlAware url, LoadOptions options, Boolean toItemOption)
Normalize a url
-
normalize
abstract List<NormUrl> normalize(Collection<UrlAware> urls, LoadOptions options, Boolean toItemOption)
Normalize urls
-
normalizeOrNull
abstract NormUrl normalizeOrNull(String url, LoadOptions options, Boolean toItemOption)
Normalize a url
-
normalizeOrNull
abstract NormUrl normalizeOrNull(UrlAware url, LoadOptions options, Boolean toItemOption)
Normalize a url
-
inject
abstract WebPage inject(String url)
Inject a url to fetch later
- Parameters:
url- The url followed by options
-
getOrNull
abstract WebPage getOrNull(String url)
Get a page from database if exists
- Parameters:
url- The url
-
exists
abstract Boolean exists(String url)
Check if a page exists in the database
- Parameters:
url- The url
-
fetchState
abstract CheckState fetchState(WebPage page, LoadOptions options)
Return the fetch state of the page
- Parameters:
page- The webpageoptions- The load options
-
open
abstract WebPage open(String url)
Open a url.
This method opens the url immediately, regardless of the previous state of the page.
- Parameters:
url- The url to open
-
load
abstract WebPage load(String url, String args)
Load a url with arguments.
This method checks the local storage first, if it exists and is good, return the persisted version, otherwise, fetch it from the Internet.
Other fetch condition can be specified in load arguments:
expiration
page size requirement
fields requirement
- Parameters:
url- The url to loadargs- The load arguments
-
load
abstract WebPage load(String url, LoadOptions options)
Load a url with options.
This method checks the local storage first, if it exists and is good, return the persisted version, otherwise, fetch it from the Internet.
Other fetch condition can be specified in load arguments:
expiration
page size requirement
fields requirement
- Parameters:
url- The url to loadoptions- The load options
-
load
abstract WebPage load(UrlAware url, String args)
Load a url with specified options
- Parameters:
url- The url to loadargs- The load args
-
load
abstract WebPage load(UrlAware url, LoadOptions options)
Load a url with options.
- Parameters:
url- The url to loadoptions- The load options
-
load
abstract WebPage load(NormUrl normUrl)
Load a url in normalized form.
- Parameters:
normUrl- The normalized url
-
loadDeferred
abstract WebPage loadDeferred(String url, LoadOptions options)
Load a url with specified options.
This function is a kotlin suspend function, which could be started, paused, and resume. Suspend functions are only allowed to be called from a coroutine or another suspend function.
- Parameters:
url- The url to loadoptions- The load options
-
loadDeferred
abstract WebPage loadDeferred(UrlAware url, String args)
Load a url with specified options.
This function is a kotlin suspend function, which could be started, paused, and resume. Suspend functions are only allowed to be called from a coroutine or another suspend function.
- Parameters:
url- The url to loadargs- The load args
-
loadDeferred
abstract WebPage loadDeferred(UrlAware url, LoadOptions options)
Load a url with specified options.
This function is a kotlin suspend function, which could be started, paused, and resume. Suspend functions are only allowed to be called from a coroutine or another suspend function.
- Parameters:
url- The url to loadoptions- The load options
-
loadDeferred
abstract WebPage loadDeferred(NormUrl normUrl)
Load a url with specified options
This function is a kotlin suspend function, which could be started, paused, and resume. Suspend functions are only allowed to be called from a coroutine or another suspend function.
- Parameters:
normUrl- The normalized url
-
loadAll
abstract List<WebPage> loadAll(Iterable<String> urls, LoadOptions options)
Load all urls with specified options, this causes a parallel fetching whenever applicable
- Parameters:
urls- The urls to loadoptions- The load options
-
loadAll
abstract List<WebPage> loadAll(Iterable<NormUrl> normUrls)
Load all urls with specified options
- Parameters:
normUrls- The urls to load
-
loadAsync
abstract CompletableFuture<WebPage> loadAsync(NormUrl url)
Load a url with java async style
- Parameters:
url- The url to load
-
loadAllAsync
abstract List<CompletableFuture<WebPage>> loadAllAsync(Iterable<NormUrl> urls)
Load all urls with specified options with java async style
- Parameters:
urls- The urls to load
-
submit
abstract PulsarSession submit(UrlAware url)
Submit a url to the url pool, the url will be processed in the main crawl loop later
- Parameters:
url- The url to submit
-
submitAll
abstract PulsarSession submitAll(Iterable<UrlAware> urls)
Submit the urls to the url pool, the submitted urls will be processed in the main crawl loop later
- Parameters:
urls- The urls to submit
-
loadOutPages
abstract List<WebPage> loadOutPages(String portalUrl, String args)
Load out pages linked from the portal page
- Parameters:
portalUrl- The portal url from where to load pagesargs- The load args
-
loadOutPages
abstract List<WebPage> loadOutPages(String portalUrl, LoadOptions options)
Load out pages linked from the portal page
- Parameters:
portalUrl- The portal url from where to load pagesoptions- The load options
-
loadOutPagesAsync
abstract List<CompletableFuture<WebPage>> loadOutPagesAsync(String portalUrl, LoadOptions options)
Load out pages linked from the portal page
- Parameters:
portalUrl- The portal url from where to load pagesoptions- The load options
-
submitOutPages
abstract AbstractPulsarSession submitOutPages(String portalUrl, String args)
Submit the urls of out pages in the portal page, the submitted urls will be processed in the main crawl loop later
- Parameters:
portalUrl- The portal url from where to load pagesargs- The load arguments
-
submitOutPages
abstract PulsarSession submitOutPages(String portalUrl, LoadOptions options)
Submit the urls of out pages in the portal page, the submitted urls will be processed in the main crawl loop later
- Parameters:
portalUrl- The portal url from where to load pagesoptions- The load options
-
loadResource
abstract WebPage loadResource(String url, String referer, String args)
Load a url as a resource without browser rendering in the browser context
This function is a kotlin suspend function, which could be started, paused, and resume. Suspend functions are only allowed to be called from a coroutine or another suspend function.
- Parameters:
url- The url to loadargs- The load arguments
-
loadResource
abstract WebPage loadResource(String url, String referer, LoadOptions opts)
Load a url as a resource without browser rendering in the browser context
This function is a kotlin suspend function, which could be started, paused, and resume. Suspend functions are only allowed to be called from a coroutine or another suspend function.
- Parameters:
url- The url to loadopts- The load options
-
parse
abstract FeaturedDocument parse(WebPage page, Boolean noCache)
Parse the Web page into DOM. If the Web page is not changed since last parse, use the last result if available
-
loadDocument
abstract FeaturedDocument loadDocument(String url, String args)
Load or fetch a webpage and parse it into a document
-
loadDocument
abstract FeaturedDocument loadDocument(String url, LoadOptions options)
Load or fetch a webpage and parse it into a document
-
loadDocument
abstract FeaturedDocument loadDocument(NormUrl normUrl)
Load or fetch a webpage and parse it into a document
-
scrape
abstract Map<String, String> scrape(String url, String args, Iterable<String> fieldSelectors)
Scrape a webpage
-
scrape
abstract Map<String, String> scrape(String url, LoadOptions options, Iterable<String> fieldSelectors)
Scrape a webpage
-
scrape
abstract Map<String, String> scrape(String url, String args, Map<String, String> fieldSelectors)
Scrape a webpage
-
scrape
abstract Map<String, String> scrape(String url, LoadOptions options, Map<String, String> fieldSelectors)
Scrape a webpage
-
scrape
abstract List<Map<String, String>> scrape(String url, String args, String restrictSelector, Iterable<String> fieldSelectors)
Scrape a webpage
-
scrape
abstract List<Map<String, String>> scrape(String url, LoadOptions options, String restrictSelector, Iterable<String> fieldSelectors)
Scrape a webpage
-
scrape
abstract List<Map<String, String>> scrape(String url, String args, String restrictSelector, Map<String, String> fieldSelectors)
Scrape a webpage
-
scrape
abstract List<Map<String, String>> scrape(String url, LoadOptions options, String restrictSelector, Map<String, String> fieldSelectors)
Scrape a webpage
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, String args, Iterable<String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromargs- The load argumentsfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, LoadOptions options, Iterable<String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromoptions- The load optionsfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, String args, String restrictSelector, Iterable<String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromargs- The load argumentsrestrictSelector- The selector used to restrict all fields to be inside the DOMfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, LoadOptions options, String restrictSelector, Iterable<String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromoptions- The load optionsrestrictSelector- The selector used to restrict all fields to be inside the DOMfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, String args, Map<String, String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromargs- The load argumentsfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, LoadOptions options, Map<String, String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromoptions- The load optionsfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, String args, String restrictSelector, Map<String, String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromargs- The load argumentsrestrictSelector- The selector used to restrict all fields to be inside the DOMfieldSelectors- The CSS selectors to extract fields from out pages
-
scrapeOutPages
@ExperimentalApi() abstract List<Map<String, String>> scrapeOutPages(String portalUrl, LoadOptions options, String restrictSelector, Map<String, String> fieldSelectors)
Scrape out pages using given selectors.
- Parameters:
portalUrl- The portal url the scraping start fromoptions- The load optionsrestrictSelector- The selector used to restrict all fields to be inside the DOMfieldSelectors- The CSS selectors to extract fields from out pages
-
getVariable
abstract Object getVariable(String name)
Get a variable associated with this session
-
setVariable
abstract Unit setVariable(String name, Object value)
Set a variable associated with this session
-
putSessionBean
@Deprecated(message = Not used any more) abstract Unit putSessionBean(Object obj)
Put session scope bean
-
export
abstract Path export(WebPage page, String ident)
Export the content of a webpage.
- Parameters:
page- Page to exportident- File name identifier used to distinguish from other names
-
export
abstract Path export(FeaturedDocument doc, String ident)
Export the outer HTML of the document.
- Parameters:
doc- Document to exportident- File name identifier used to distinguish from other names
-
exportTo
abstract Path exportTo(FeaturedDocument doc, Path path)
Export the whole HTML of the document to the given path.
- Parameters:
doc- Document to exportpath- Path to save the exported content
-
getId
abstract Integer getId()
The session id. Session id is expected to be set by the container, e.g. the h2 database runtime
-
getContext
abstract PulsarContext getContext()
The pulsar context
-
getSessionConfig
abstract VolatileConfig getSessionConfig()
The session scope volatile config, every setting is supposed to be changed at any time and any place
-
getUnmodifiedConfig
abstract ImmutableConfig getUnmodifiedConfig()
-
getSessionBeanFactory
abstract BeanFactory getSessionBeanFactory()
The scoped bean factory: for each volatileConfig object, there is a bean factory
-
getDisplay
abstract String getDisplay()
A short descriptive display text.
-
getPageCache
abstract ConcurrentExpiringLRUCache<String, WebPage> getPageCache()
The global page cache
-
getDocumentCache
abstract ConcurrentExpiringLRUCache<String, FeaturedDocument> getDocumentCache()
The global document cache
-
getGlobalCache
abstract GlobalCache getGlobalCache()
The global cache
-
getGlobalCacheFactory
abstract GlobalCacheFactory getGlobalCacheFactory()
-
-
-
-