ReContent
Library for parsing sites using a strict system of rules-selectors.
Connection
- Add jitpack repository in your root build.gradle at the end of repositories:
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency:
dependencies {
implementation 'com.github.0gdump:android-recontent:0.2'
}
Usage
-
To start, initialize Recontent:
val reсontent = ReContent().init(this)
-
Create a rule structure. The site is parsed with blocks described by the RootParser structure, inside which there is a list of rules with selector and callback
reсontent.setupRules({ rules.add( RootParser( rootSelector = "div#entrytext.j-e-text", textNodeRule = TextNodeRule(callback = { tn -> buildText(tn) }), rules = listOf( Rule( selector = "span.j-imagewrapper", callback = { e: Element, t: String? -> buildImage(e, t) } ) ) ) ) })
-
Load url
recontent.load(url)
-
Watch the magic!
Demo
To view a demo application that demonstrates the library's capabilities, open the project, the demo module. The screenshots show the site view and converted using the library:
Notes
JSoup and WebView are used under the hood. Loading and parsing performance is not guaranteed and has not been measured. The library was created for research purposes
License
The library is distributed under Apache License 2.0