Created
March 14, 2016 15:10
-
-
Save kspeeckaert/ec7353a0ab53ae4cc3a8 to your computer and use it in GitHub Desktop.
Create a Markdown link from a URL, using the page's title as link description
This file contains 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
import requests | |
from bs4 import BeautifulSoup | |
import sys | |
def get_content(url): | |
r = requests.get(url) | |
r.raise_for_status() | |
return r.text | |
def create_md_link(title, url): | |
return '[{}]({})'.format(title, url) | |
if __name__ == '__main__': | |
url = sys.argv[1] | |
soup = BeautifulSoup(get_content(url), 'lxml') | |
title = soup.head.title.string | |
md_link = create_md_link(title, url) | |
print(md_link, end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment