22 November 2026
The day rice cost Tk 3,77,922
My scraper said rice cost three lakh taka. How one typo, one catch-all regex and one honest friend taught me to make every match earn its place.
My scraper told me, with complete confidence, that rice in Dhaka cost three lakh seventy-seven thousand taka.
It wasn’t crashing. It wasn’t throwing errors. It had happily read a newspaper article, found the word “rice”, found a number with “Tk” in front of it, and written the two down next to each other. The number was from a paragraph about the national budget.
That was the moment I stopped trusting my own code, and it’s the most useful thing that happened in the whole project.
Why I was scraping rice prices at all
I was building something to connect rice suppliers with last-mile shops, and I wanted a wow-factor: let grocers see today’s market prices so they could buy and sell smarter.
Bangladesh has no easy, machine-readable monthly price list for everyday staples like rice, lentils, eggs, onions and oil. The prices do exist. They’re just buried in news reports, in sentences like “coarse rice sold for Tk 52–56 a kilo at city kitchen markets.” Mixed in with them are Bangla words (chal for rice, murgi for chicken, কেজি for kilo, টাকা for taka) and units that change from line to line: kilo, litre, hali (four eggs), apiece.
I wanted a simple table: month, product, price, retail or wholesale, and where the number came from.
Attempt one: ask Google
The first version was 333 lines and very optimistic. For each of 46 commodities and each month, it searched Google and grabbed the first price-looking thing in the snippets.
It ran straight into CAPTCHAs. My “solution” was to have the script pause for up to two minutes so I could solve them by hand. That didn’t go so well. I had, in my infinite wisdom, added an obnoxious alarm that was hard to miss whenever the script needed my input. I thought it was alright until everyone in the room started petitioning for an eviction.
Worse, even when it worked, I had no idea which article a price came from or which month it described. A number with no source isn’t data.
Lesson one, which I learned before writing any clever code: pick the source before you optimise the scraper.
Attempt two: go to the primary source
The newspaper has a daily archive. One page per day, every article listed. So version two walked it day by day: open the archive page, scroll until the list stops growing, open each article that looks like a market report, and pull out prices.
I split the date range across worker threads, each running its own headless browser, and it felt fast and grown-up. Every price now came with its article URL, title and date. Provenance was built in.
And then rice cost Tk 3,77,922.
I’d been watching the totals climb and feeling productive. The output folder filled up with out.csv files (so creative, I know), and every new one put a little more spring in my step. So I showed it off to a friend, who asked the reasonable question: how good are the prices, actually?
I should have looked at the values before I looked proud. I opened the files. Potatoes cost Taka Shariatpur (a district in Bangladesh, not a number). Rice cost over Tk 370,000, when a kilo usually runs Tk 80–100.
My pride survived right up until my friend asked how many years of inflation it would take to get there.
What was actually happening
The extractor ran six regular expressions over the whole article. If any commodity name appeared within 500 characters of a price, the price was assigned to it. Five of those patterns were careful ones that required a unit (“per kg”, “a hali”). The sixth was a catch-all: just Tk followed by a number.
The careful patterns had a typo. Where I meant \s* (optional whitespace), I’d written ?s*. One character. It meant the unit-bearing patterns essentially never matched, so every single price was coming from the catch-all. And a 1,000-character window around the word “rice” in a budget story contains a lot of numbers.
On a two-day sample, the extractor produced 105 prices. One of them had a unit.
The fix was deleting things
The rewrite was mostly about saying no.
- Think in sentences, not windows. Split the article into sentences and only pair a commodity with a price in the same sentence.
- Anchor on how reporters actually write. “sold for Tk…”, “retailed at Tk…”, “at Tk… a kilo”. These were ordered from most to least reliable.
- No unit, no price. Every pattern had to end in kg, kilo, litre, hali, piece, dozen, or the Bangla equivalents. Ranges like “52–56”, “52 to 56” and “৫২ থেকে ৫৬” were allowed.
- Ignore changes. “Prices rose by Tk 10” is not a price. Skip it.
- Only borrow from a neighbouring sentence if it mentions no other commodity, and mark that match as lower-confidence.
- Delete the catch-all. My comment in the code just says it “causes too many false positives”. That’s underselling it.
Same two days, same articles: 105 prices became 12. All 12 had units. “Tk 52–56 a kilo.” “Tk 44–45 a hali.” Things a human would actually write down.
Fewer results felt like going backwards. It was the first time the output was true.
The part I only found a year later
When I went back through this code recently to write this post, I tested the Bangla handling properly for the first time.
I’d built a dictionary with English, transliterated and Bangla names for 31 commodities: egg, dim, ডিম. I was proud of it. It turns out JavaScript’s \b (word boundary) only understands ASCII letters, so a pattern like \bচিনি\b never matches Bangla text. Neither does \d match Bangla digits (০–৯). My lovingly built Bangla vocabulary had never matched a single sentence. Everything that worked was coming through the English words.
It also turned out that “ada” (ginger) matches “Canada”.
I’m leaving this in because it’s the same lesson as the rice, one level deeper: the code that looks most complete is the code you’ve tested least.
What I’d tell myself at the start
- Find a source that gives you provenance for free, before you write a line of scraping code.
- A general pattern that “catches everything” is a bug factory. Make every match earn its place.
- Measure on the same input before and after. “105 → 12” convinced me more than any amount of reasoning.
- If your language isn’t English, test your regexes in it. Don’t assume.
The price scraper was a great project for me. It also got me curious about a different split of the work: let a small language model steer while plain code does the scraping. That turned out to be cheaper, more token-efficient, and kinder on my nerves. Tokens were saved (alongside tears), and it paved the way into RAG workflows and a lot more. But that’s another story.