wikicrawl/app/browser.py

38 lines
1.4 KiB
Python
Raw Normal View History

# browser module defines functions for creating selenium webdriver
# objects. The way this works is selenium is a third-party library
# that gives a common interface for interacting with web browsers,
# i.e. chrome, firefox, internet explorer, and even a pseudo-browser.
#
# This library (selenium) creates a web browser process
# (chrome will actually fire up for you to see) and gives you
# a webdriver object interface to programmatically control the browser.
# You can do things like click on links, extract information from the
# page, pass control to a user... the limit is your imagination.
2017-08-17 01:27:05 -06:00
import selenium
import selenium.webdriver
import logging
from . import config
2017-08-17 01:27:05 -06:00
# This function has a parameter (driver) that passes in a value. In this case,
# this driver variable defaults to the string 'chrome'. The code can call
# create_webdriver() which is the same as create_webdriver('chrome') but
# can alternatively call create_webdriver('firefox') and get different
# functionality.
2017-08-17 01:45:07 -06:00
def create_webdriver(driver='chrome'):
if driver == 'chrome':
return create_webdriver_chrome()
elif driver == 'firefox':
return create_webdriver_firefox()
def create_webdriver_firefox():
pass
def create_webdriver_chrome():
2017-08-17 01:27:05 -06:00
opt = selenium.webdriver.chrome.options.Options()
opt.add_argument('--user-agent=' + config.obj.WEBDRIVER_USER_AGENT)
2017-08-17 01:27:05 -06:00
driver = selenium.webdriver.Chrome(chrome_options = opt)
return driver