
How to Scrape Medium Articles and Author Stats with Python
Medium hosts millions of articles with engagement data. Scraping it helps analyze content strategies and benchmark authors. Hidden JSON Endpoints Append ?format=json to URLs. Response has anti-XSRF prefix ]}while(1);</x> : import requests , json , time from datetime import datetime class MediumScraper : def __init__ ( self ): self . s = requests . Session () self . s . headers . update ({ " User-Agent " : " Mozilla/5.0 " , " Accept " : " application/json " }) def _json ( self , text ): pfx = " ]}while(1);</x> " return json . loads ( text [ len ( pfx ):] if text . startswith ( pfx ) else text ) def profile ( self , user ): d = self . _json ( self . s . get ( f " https://medium.com/@ { user } ?format=json " ). text ) u = d . get ( " payload " ,{}). get ( " user " ,{}) return { " name " : u . get ( " name " ), " followers " : u . get ( " socialStats " ,{}). get ( " followerCount " , 0 )} def posts ( self , user , limit = 25 ): d = self . _json ( self . s . get ( f " https://medium.com/@ {
Continue reading on Dev.to Tutorial
Opens in a new tab



![[MM’s] Boot Notes — The Day Zero Blueprint — Test Smarter on Day One](/_next/image?url=https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1368%2F1*AvVpFzkFJBm-xns4niPLAA.png&w=1200&q=75)