fix(title): pick best <title> when a page has multiple (Medium fix) - #11
Merged
Conversation
Medium serves two <title> tags on article pages, one of which is a bare site name (<title>Medium</title>). In the non-JS HTML our scraper receives that bare tag can come first, so get_title() picked "Medium" as the post title. Instead of blindly using title_element[0], choose the best candidate among all <title> tags: prefer the one whose filtered text contains og:title, otherwise the longest. Single-title pages are unaffected.
idoshamun
approved these changes
Jul 23, 2026
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.
Problem
Recently-scraped Medium articles are being stored with the title
Medium.Medium serves two
<title>tags on article pages — the real one (… | by Author | … | Medium) and a bare<title>Medium</title>. In the non-JS HTML our scraper (post-scraper-one-ai/ yggdrasil via thisnewspaperfork) receives, the bare tag can appear first, andget_title()blindly usedtitle_element[0]→Medium.Fix
Instead of always taking the first
<title>, choose the best candidate among all<title>tags:og:title(the descriptive article title), elseThe existing
|/-splitter then trims the| by … | Mediumsuffix as before. Single-<title>pages are unaffected.Verification
Ran against the real Medium article HTML (both tag orderings) + a normal single-title page:
Notes / follow-up
This handles the reachable-article case. Genuinely walled/404 Medium pages still only contain
<title>Medium</title>(no real title tag), so a defensive guard inpost-scraper-one-aito reject a final title ofMedium/Just a moment...is still worth adding separately.