splish
package splish
- Alphabetic
- Public
- All
Type Members
-
case class
Splash(splashHost: String = "localhost", splashPort: Integer = 8050, splashUser: String = null, splashPassword: String = null, useSSL: Boolean = false) extends Product with Serializable
A class to facilitate access to a Splash instance.
A class to facilitate access to a Splash instance.
Splash is a javascript rendering service. It’s a lightweight web browser with an HTTP API, implemented in Python 3 using Twisted and QT5. The (twisted) QT reactor is used to make the service fully asynchronous allowing to take advantage of webkit concurrency via the QT main loop.
- splashHost
the host name or IP address of the Splash instance. Defaults to "
localhost
"- splashPort
the port number the Splash instance is running on. Defaults to
8050
- splashUser
the username use if authentication is enabled in the Splash instance. Keep
null
for no authentication- useSSL
if
true
the connection to the Splash intance will be made overHTTPS
import splish.Splash Splash().renderHTML("https://https://www.scala-lang.org/")
- See also
Example:
Value Members
- object SplashMain
This is the documentation for the
splish
library.Package Information
The splish package contains a single class splish.Splash with methods for interacting with a ScrapingHub Splash instance.
If you haven’t hit the above link yet and are unfamilar with Splash, the TLDR is that it’s an alternative to Selenium in that it’s a full browser and executes javascript. The full rendering engine is based on Qt Webkit and Splash instances have a REST API that provides a ton of flexibility when needed and ease of use for more casual scraping tasks.
You can get it up and running locally with Docker via:
If you've built the source and run
sbt packInstall
, you can start playing withsplash
on the command line via~/local/bin/splash-main
. Here's the help:The first thing we need to do is make a connection to the server
We can test that connection and get some other information as well:
The library makes use of [
uJson
](http://www.lihaoyi.com/upickle/#uJson) for more complex return types and a few methods return arequests
[Response
](https://github.com/lihaoyi/requests-scala/blob/master/requests/src/requests/Model.scala#L235-L276) object due to the result of a call to more dynamic endpoints being un-knowable at call time (Splash allows you to useLua
to perform complex page interaction and you can return images, plaintext, HTML or JSON via the Lua interface).The classic use case for Splash is to feed it a URL and get HTML back after it’s had time to process any javascript. The URL in the following example relies on javascript to add content to the page:
Here’s what that looks like just using the
requests
library:Most of the other Splash API endpoints have corresponding methods in the library (the image-oriented ones are on the TODO list). We can get the same page in both Splash JSON:
and HAR formats: