Skip to content

Instantly share code, notes, and snippets.

@py-ranoid
Last active December 27, 2018 05:19
Show Gist options
  • Save py-ranoid/e53ad0bb3dfdaa96dff7dbd7f0764b0f to your computer and use it in GitHub Desktop.
Save py-ranoid/e53ad0bb3dfdaa96dff7dbd7f0764b0f to your computer and use it in GitHub Desktop.
Fetching a website's source (HTML) with Selenium over Python.
from selenium import webdriver,common
"""
How to Download Chrome Driver :
- Go to https://chromedriver.storage.googleapis.com/index.html?path=2.45/
- Download and unzip webdriver for your OS
- Move the webdriver to a where it can be accessed by python. (Same directory or $PATH)
"""
try :
browser = webdriver.Chrome()
except common.exceptions.WebDriverException as e:
print ("Download Chrome Webdriver\n"+e.message)
exit()
def get_page_html(url="www.github.com"):
browser.get(url)
return browser.page_source
if __name__ == "__main__":
print (get_page_html())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment