Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2017 02:51
Show Gist options
  • Save anonymous/2359b88fcbd6c95a44a3432ac3156c07 to your computer and use it in GitHub Desktop.
Save anonymous/2359b88fcbd6c95a44a3432ac3156c07 to your computer and use it in GitHub Desktop.
python save screenshot to file, robobrowser python 3.6
import random
import webbrowser
from robobrowser import RoboBrowser
def html_fixer(html_source: str):
trans_table = {ord(c): None for c in u'\r\n\t'}
src_list = [html_source]
html_source = ' '.join(s.strip().translate(trans_table) for s in src_list)
html_source = " ".join(html_source.split())
return html_source
def save_html_to_file(r: RoboBrowser, file_name=str(random.randint(100000, 999999)) + '.html', open_=True):
data = html_fixer(r.response.text)
with open(file=file_name, mode='w', encoding="utf-8") as f:
f.write(data)
if open_ is True:
webbrowser.open(file_name, new=2)
if __name__ == '__main__':
browser = RoboBrowser()
browser.open('http://github.com')
save_html_to_file(browser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment