Skraper
Kotlin/Java library and cli tool for scraping posts and media from various sources with neither authorization nor full page rendering (Facebook, Instagram, Twitter, Youtube, Tiktok, Telegram, Twitch, Reddit, 9GAG, Pinterest, Flickr, Tumblr, Coub, Vimeo, IFunny, VK, Odnoklassniki, Pikabu)
Install / Use
/learn @sokomishalov/SkraperREADME
Skraper
~~Here should be some fancy logo~~
Overview
Kotlin/Java library and cli tool which allows scraping and downloading posts, attachments, other meta from more than 10 sources without any authorization or full page rendering. Based on jsoup, jackson and kotlin-coroutines.
Repository contains:
Current list of implemented sources:
- Youtube
- TikTok
- Telegram
- Twitch
- 9GAG
- Flickr
- Tumblr
- Vimeo
- IFunny
- Coub
- VK
- Odnoklassniki
- Pikabu
Bugs
Unfortunately, each web-site is subject to change without any notice, so the tool may work incorrectly because of that. If that happens, please let me know via an issue.
Cli tool
Cli tool allows to:
- download media with flag
--media-onlyfrom almost all presented sources. - scrape posts meta information
Requirements:
- Java: 1.8 +
- Maven (optional)
Build tool
./mvnw clean package -DskipTests=true
Usage:
./skraper --help
usage: [-h] PROVIDER PATH [-n LIMIT] [-t TYPE] [-o OUTPUT] [-m]
[--parallel-downloads PARALLEL_DOWNLOADS]
optional arguments:
-h, --help show this help message and exit
-n LIMIT, --limit LIMIT posts limit (50 by default)
-t TYPE, --type TYPE output type, options: [log, csv, json, xml, yaml]
-o OUTPUT, --output OUTPUT output path
-m, --media-only scrape media only
--parallel-downloads PARALLEL_DOWNLOADS amount of parallel downloads for media items if
enabled flag --media-only (4 by default)
positional arguments:
PROVIDER skraper provider, options: facebook, instagram,
twitter, youtube, tiktok, telegram, twitch, reddit,
9gag, pinterest, flickr, tumblr, ifunny, vk, pikabu,
vimeo, odnoklassniki, coub
PATH path to user/community/channel/topic/trend
Examples:
./skraper 9gag /hot
./skraper reddit /r/memes -n 5 -t csv -o ./reddit/posts
./skraper instagram /explore/tags/memes -t json
./skraper flickr /photos/harrythehawk -t yaml
./skraper pinterest /levato/meme -t xml
./skraper youtube /user/JetBrainsTV/videos --media-only -n 2
Kotlin Library
Distribution
Maven:
<dependency>
<groupId>ru.sokomishalov.skraper</groupId>
<artifactId>skrapers</artifactId>
<version>x.y.z</version>
</dependency>
Gradle kotlin dsl:
implementation("ru.sokomishalov.skraper:skrapers:x.y.z")
Usage
Instantiate specific scraper
As mentioned before, the provider implementation list is:
- FacebookSkraper
- InstagramSkraper
- TwitterSkraper
- YoutubeSkraper
- TikTokSkraper
- TelegramSkraper
- TwitchSkraper
- RedditSkraper
- NinegagSkraper
- PinterestSkraper
- FlickrSkraper
- TumblrSkraper
- VimeoSkraper
- IFunnySkraper
- CoubSkraper
- VkSkraper
- OdnoklassnikiSkraper
- PikabuSkraper
After that usage as simple as is:
val skraper = InstagramSkraper(client = OkHttpSkraperClient())
Important moment: it is highly recommended to not use DefaultBlockingSkraperClient . There are some more efficient, non-blocking and resource-friendly implementations for SkraperClient. To use them you just have to put required dependencies in the classpath.
Current http-client implementation list:
- DefaultBlockingClient: simple java.net.* blocking api implementation
- OkHttpSkraperClient: okhttp3 implementation
- SpringReactiveSkraperClient: spring-webflux client implementation
- KtorSkraperClient: ktor-client-jvm implementation
Available methods
Each scraper is a class which implements Skraper interface:
interface Skraper {
val client: SkraperClient
fun getPosts(path: String): Flow<Post>
suspend fun getPageInfo(path: String): PageInfo?
fun supports(media: Media): Boolean
suspend fun resolve(media: Media): Media
}
Also, there are some provider-specific kotlin extensions for implementations. You can find them out at the provider implementation package.
Usage from plain Java
There is an out-of-box java interop utility class ru.sokomishalov.skraper.util.JavaInterop:
class Example {
public static void main(String[] args) {
Skraper skraper = new InstagramSkraper();
List<Post> posts = JavaInterop.limitedFlow(skraper.getPosts("/memes.video"), 10);
PageInfo info = JavaInterop.callBlocking(cont -> skraper.getPageInfo("/memes.video", cont));
}
}
Scrape user/community/channel/topic/trend posts
To scrape the latest posts for specific user, channel or trend use skraper like that:
suspend fun main() {
val skraper = FacebookSkraper()
val posts = skraper.getUserPosts(username = "memes").take(2).toList() // extension for getPosts()
// or
val postsDetected = Skrapers.getPosts(url = "https://facebook.com/memes") // aggregating singleton
println(JsonMapper().writerWithDefaultPrettyPrinter().writeValueAsString(posts))
}
Received data structure is similar to each other provider's. Output data example:
[
{
"id": "5029851093699104",
"text": "gotta love em!",
"publishedAt": 1580744400000,
"statistics": {
"likes": 79,
"comments": 3
},
"media": [
{
"url": "https://facebook.com/memes/posts/5029851093699104?__xts__%5B0%5D=68.ARA2yRI2YnlXQRKX7Pdphh8ztgvnP11aYE_bZFPNmqLpJZLhwJaG24gDPUTiKDLv-J_E09u2vLjCXalpmEuGSmVR0BkVtcng_i6QV8x5e-aZUv0Mkn1wwKLlhp5NNH6zQWKlqDqRjZrwvcKeUi0unzzulRCHRvDIrbz2leM6PLescFySwMYbMmKFc7ctqaC_F7nJ09Ya0lz9Pqaq_Rh6UsNKom6fqdgHAuoHV894a3QRuyY0BC6fQuXZLOLbRIfEVK3cF9Z5UQiXUYruCySF-WpQEV0k72x6DIjT6B3iovYFnBGHaji9VAx2PByZ-MDs33D1Hz96Mk-O1Pj7zBwO6FvXGhkUJgepiwUOVd0q-pV83rS5EhjtPFDylNoNO2xkDUSIi483p49vumVPWtmab8LX1V6w2anf55kh6pedCXcH3D8rBjz8DaTBnv995u9kk5im-1-HdAGQHyKrCZpaA0QyC-I4oGsCoIJGck3RO8u_SoHcfe2tKjTgPe6j9p1D&__tn__=-R",
"aspectRatio": 0.864,
"duration": 10860.000000000
}
]
},
{
"id": "4990218157662398",
"text": "Interesting",
"publishedAt": 1580742000000,
"statistics": {
"likes": 3092,
"comments": 514
},
"media": [
{
"url": "https://scontent.fhrk1-1.fna.fbcdn.net/v/t1.0-0/p526x296/52333452_10157743612509879_529328953723191296_n.png?_nc_cat=1&_nc_ohc=oNMb8_mCbD8AX-w9zeY&_nc_ht=scontent.fhrk1-1.fna&oh=ca8a719518ecfb1a24f871282b860124&oe=5E910D0C",
"aspectRatio": 0.89605734
Related Skills
node-connect
328.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
81.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
328.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
81.0kCommit, push, and open a PR
