Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99408

Applying functions with a Headless WebDriver

$
0
0

Using the Selenium library, I am looking to run a headless WebDriver but I get a NameError. The following code should just retrieve a site's HTML code.

NameError: name 'options' is not defined

I attempted to clear my code using several functions in hopes to run multiple scripts together.

#coding: utf-8
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options


class WebDriver:

    def __init__(self):
        self.setup()
        self.extractor()
        self.teardown_module()

    def setup(self):
        self.options = Options()
        self.options.headless = True
        self.driver = webdriver.Chrome('/Users/user/Documents/docs/chromedriver', chrome_options=options)
        self.driver.get('https://google.com/')
        self.driver.page_source

    def teardown_module(self):
        self.driver.quit()

page = WebDriver()
page.driver

Viewing all articles
Browse latest Browse all 99408

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>