Atri Mukherjee

byomkesh

A courteous truth-seeker for news article text.

Facts

library(byomkesh)

byomkesh("links.csv",
  "news.jsonl",
  patterns = "charli\\s*xcx")
Fig. 1 Code
Fig. 2 Articles collected (schematic)

What it is

byomkesh is a text scraper for news research, written as an R package. It takes a list of news URLs, for example a Media Cloud export, and brings back the full text of each article, together with metadata and counts of your keywords. It is built for media and communication researchers who want news texts for qualitative, quantitative and computational analyses, and it is named after Sharadindu Bandyopadhyay's detective Byomkesh Bakshi. It is my first open-source tool, so expect the occasional bug.

How it works

  1. You supply a CSV with a url column (and optionally an id column).
  2. For each link, byomkesh reads the site's robots.txt and waits between visits to the same site.
  3. It downloads the page and extracts the article text and metadata.
  4. It counts your keywords (any script, Devanagari included) and saves the surrounding passages.
  5. If a story has been taken down, it can look for a copy in the Internet Archive.
  6. Results are written line by line, so a stopped run carries on where it left off.

Use

install.packages("byomkesh", repos = c("https://atrimukherjee.r-universe.dev",
                                       "https://cloud.r-project.org"))
library(byomkesh)

byomkesh("my_links.csv", "my_articles.jsonl",
         email    = "you@university.edu",
         patterns = "your keyword")

articles <- read_results("my_articles.jsonl")

The README in the repository has a worked example, all options, and a command-line version for long runs.

Output

One row per link, as JSONL or CSV: the final URL, a status (ok, http_error, robots_blocked and so on), fetch time, title, author, date, language, word count, keyword hits, context passages and the full text.

Stack

R (4.1 or newer) with httr, xml2, jsonlite and digest.

Limitations

Ethics and legal note

byomkesh honours robots.txt and Crawl-delay, pauses between visits, identifies you by email so site owners can reach you, and records pages that robots rules exclude instead of fetching them. Switching off the robots check is only for sites that have given permission. Please also check each site's terms of service before collecting from it. Article texts belong to their publishers: use them for analysis and, when sharing data, share links, codes or counts rather than full texts. If texts include personal data such as names of private individuals, data protection law (GDPR in the EU) applies to how you store and share them, and your ethics board or data protection officer should be consulted.