Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert HTML to text #4

Closed
remram44 opened this issue Jan 26, 2014 · 2 comments
Closed

Convert HTML to text #4

remram44 opened this issue Jan 26, 2014 · 2 comments

Comments

@remram44
Copy link
Owner

Some emails might be HTML, we need to convert that to a readable text version.

@remram44
Copy link
Owner Author

BeautifulSoup is surprisingly bad at this. Any ideas?

html = '<p>T<i>e</i>st <b>haha</b></p><p>Other\nline</p>'

from bs4 import BeautifulSoup
BeautifulSoup(html).get_text()
# 'Test hahaOther\nline'
BeautifulSoup(html).get_text(' ')
# 'T e st  haha Other\nline'
BeautifulSoup(html).get_text('\n')
# 'T\ne\nst \nhaha\nOther\nline'

@remram44
Copy link
Owner Author

Aaron Swartz's html2text seems close enough.

from html2text import HTML2Text
HTML2Text().handle(html)
# 'T_e_st **haha**\n\nOther line\n\n'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant