open webpage python code example

Example 1: how to open a website in python

import webbrowser
webbrowser.open('https://www.google.co.uk/')

Example 2: python get webpage source

import requests

url = input('Webpage to grab source from: ')
html_output_name = input('Name for html file: ')

req = requests.get(url, 'html.parser')

with open(html_output_name, 'w') as f:
    f.write(req.text)
    f.close()

Example 3: open web page in python

import webbrowser

webbrowser.open('http://example.com')  # Go to example.com