Add Drugs.com scraper and tests - #13
Open
NaitikOza wants to merge 3 commits into
Open
Conversation
NaitikOza
marked this pull request as draft
July 28, 2026 01:50
NaitikOza
marked this pull request as ready for review
July 29, 2026 17:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds a Drugs.com scraper to the datasets scraping pipeline. Like the existing source scrapers, discovery and extraction are separate, and every page is normalized into a
ScrapedDocument.Drugs.com does not expose an API for drug monographs, so discovery crawls the public alphabetical index (
/alpha) and extracts links to supported drug-information pages. Extraction then downloads each page, removes site navigation and boilerplate, converts the article to normalized markdown, and records structured metadata for downstream retrieval.The scraper supports both full-corpus crawling and scraping a single document by URL.
Discovery
Discovery walks the public alphabetical index:
Some indexes (such as
0-9) skip the two-letter layer and directly contain drug pages, so both layouts are handled automatically.Supported page namespaces include:
/drug-name.html)mtmconspromonographcdiURLs are normalized into a unique page reference before scraping, and non-document pages (drug information landing pages, interaction checkers, image galleries, etc.) are filtered during discovery.
Extraction
Each page is downloaded once and converted into normalized markdown.
During extraction the scraper:
removes navigation, advertisements, footers, scripts, and other page chrome
converts HTML into clean markdown
preserves absolute links
preserves images as absolute markdown image URLs
extracts structured metadata including:
removes repeated site boilerplate
removes citation markers
truncates "More about..." sections
removes unrelated sections such as "Related drugs" and interaction pages
normalizes whitespace and markdown formatting
Pages that cannot be parsed or contain no usable content are logged and skipped without aborting the scrape.
CLI
The scraper supports both corpus mode and single-page mode.
--source allalso includes Drugs.com alongside the other supported scrapers.Licensing
Drugs.com content is proprietary.
Each document records this in its metadata rather than assigning an open license, allowing downstream users to distinguish proprietary content from open datasets.
Shared scraper improvements
While implementing the Drugs.com scraper, several shared scraping utilities were improved:
cli.py--source allbehaviorbase.pyscrape_listing_documents()now supports scrapers that returnNonefor invalid or skipped pageshtml.pyTests
Added comprehensive offline tests covering:
All tests use mocked HTTP responses (
httpx.MockTransport) and run completely offline.All scraper, HTML helper, base utility, and CLI tests pass.
Notes for review