As title, I want to practice encapsulation of programing, and I have a problem about the code I write.
The browser always automatically opens when I call the class(CrawlerSetting), and I guess which code causes the situation (browser = wb.Chrome(options=options)), but I have no idea how to avoid this situation.
Here is my code:
from selenium import webdriver as wb
class CrawlerSetting:
'''
Description:
chrome 84 version
'''
options = wb.ChromeOptions()
options.add_experimental_option('excludeSwitches', ["enable-automation"])
global browser
browser = wb.Chrome(options=options)
def __init__(self, target):
self.target = target
def open(self):
return browser.get(self.target)
def click_xpath(self, x_path):
submit_element = browser.find_element_by_xpath(x_path)
return submit_element.click()
It's my first time to ask question, if I have any format error . Plz tell me!