Created
March 14, 2016 15:08
-
-
Save kspeeckaert/1a4c92e5ac5ed57b74a4 to your computer and use it in GitHub Desktop.
Convert an HTML table (on the clipboard) to Markdown
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
from bs4 import BeautifulSoup | |
from tabulate import tabulate | |
import xerox | |
raw_html = xerox.paste() | |
tab_html = BeautifulSoup(raw_html, 'lxml') | |
rows = [] | |
for row in tab_html.find_all('tr'): | |
cols = [x.get_text().strip() for x in row.find_all(['td', 'th'])] | |
rows.append(cols) | |
tab_md = tabulate(rows, headers='firstrow', tablefmt='pipe') | |
xerox.copy(tab_md) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment