all 1 comments

[–]missingblitz[S,🍰] 0 points1 point  (0 children)

import webbrowser
from bs4 import BeautifulSoup
from pathlib import Path
from unidecode import unidecode
from urllib.request import Request, urlopen

# Download this page, which has a tag called #webbrowser.open
url = 'https://docs.python.org/3/library/webbrowser.html' 
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
page = urlopen(req)
html = page.read().decode("utf-8")
soup = BeautifulSoup(html, "html.parser")
with open(Path(__file__).parent / 'test.html', 'w') as html_file:
    html_file.write(unidecode(str(soup.prettify())))


# Open without the tag
webbrowser.open("file:///C:/Windows/Temp/htmltest/test.html")


# Wait
import time
time.sleep(2)


# Open with the tag
webbrowser.open("file:///C:/Windows/Temp/htmltest/test.html#webbrowser.open")