Created
May 16, 2019 16:23
-
-
Save markus2120/fe32cb58fdd16e46cad89ca05498a888 to your computer and use it in GitHub Desktop.
use geckodriver for getting webpage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# core modules | |
import codecs | |
import os | |
# 3rd party modules | |
from selenium import webdriver | |
from selenium.webdriver import Firefox | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.firefox.options import Options | |
from selenium.webdriver.support import expected_conditions as expected | |
from selenium.webdriver.support.wait import WebDriverWait | |
def get_browser(): | |
"""Get the browser (a "driver").""" | |
# find the path with 'which chromedriver' | |
options = Options() | |
options.add_argument('-headless') | |
browser = Firefox(executable_path='geckodriver', options=options) | |
wait = WebDriverWait(browser, timeout=1) | |
return browser | |
save_path = os.path.expanduser('/tmp/') | |
file_name = 'file.html' | |
browser = get_browser() | |
url = "https://ipinfo.io/ip" | |
browser.get(url) | |
complete_name = os.path.join(save_path, file_name) | |
file_object = codecs.open(complete_name, "w", "utf-8") | |
html = browser.page_source | |
file_object.write(html) | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment