Skip to content

Instantly share code, notes, and snippets.

@nobleknightt
Created June 16, 2024 10:41
Show Gist options
  • Select an option

  • Save nobleknightt/1d026156c0005fa13dc43cff5f7263f7 to your computer and use it in GitHub Desktop.

Select an option

Save nobleknightt/1d026156c0005fa13dc43cff5f7263f7 to your computer and use it in GitHub Desktop.
Read Medium's member-only stories with Python
"""
Usage:
- Linux: `python3 read_medium.py MEDIUM_URL`
- Windows: `python read_medium.py MEDIUM_URL`
"""
import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
GOOGLE_CACHE_URL = 'http://webcache.googleusercontent.com/search?q=cache:'
try:
MEDIUM_URL = sys.argv[1]
except:
print('Usage:\n\tmain.py MEDIUM_URL')
# driver = webdriver.Firefox()
Options = Options()
Options.add_experimental_option('detach', True)
driver = webdriver.Chrome(options=Options)
try:
driver.get(GOOGLE_CACHE_URL + MEDIUM_URL + '&vwsrc=1')
html = driver.find_element(by=By.TAG_NAME, value='pre').text
driver.execute_script('document.getElementsByTagName("html")[0].innerHTML = arguments[0];', html)
except Exception as e:
print('Error:\n\t', e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment