DEV Community

Cover image for Dev.to Scraper made of Telegram 🌚
Illia Pyshniak
Illia Pyshniak

Posted on

Dev.to Scraper made of Telegram 🌚

I love when there is no need to wait browser/app open to read new aricle. And I love automation.

So I created DEV Telegram Channel, where you can read dev.to articles. And you can do it INSTANTLY

Wait for it.
Β Β Β Comparison: Browser | App | Instant View in Telegram

What is Instant View?

Instant View is a built-in Telegram tool which allow to read articles without huge loadtime.

Main concept of IV is a Template. It tells Telegram severs what data to cache and what to remove.

So all process is simple:

  1. Article send via Telegram
  2. Telegram check for Template
  3. Telegram scraps and caches article
  4. Pure-HTML article provided to user

What is Template?

Template is a code, which tell Telegram scraper what to do with page.

IV Template Language based on:

  • YAML syntax
  • XPath to select nodes
  • RegEx to... RegExing 🌚

This code is enough to scrap 50% articles on dev.to:

~version: "2.1"
body:     //div[@id="article-body"] # Use <div id="article-body"> as main article
title:    //h1[0] # First h1 header on page used as title
Enter fullscreen mode Exit fullscreen mode

Yes, 3 lines of code.

How to use your Template?

Once you have finished your code on My Templates page, press "View in Telegram" button. You would get something like that:
...
Now you can create IV for any article using this template: t.me/iv?url=LINK&rhash=XXX

So now we have 2 goals:

  1. Automate posting
  2. Make a pretty post and get rid of this ugly long link

What is IFTTT?

IFTTT ("if this, then that") - service, which allows you to connect different services via Applets. Applet react on Trigger and respond with Action (e.g. post in Telegram with new RSS article)
RUN.
All you need is create applet on IFTTT Platform.

Hint how to make all look pretty

You can hide all ugly links in '⁠' - narrow non-breaking space. Yes, there is a character between the quotes.
....
And as a result - a piece of perfectness:
... Doh, I don't have enough images to make XKCD reference 😒

Epilogue

Article ends, so if you don't know what to do next, you can consider:

Top comments (1)

Collapse
 
mrakcw profile image
MrakCw Dev

πŸ”₯