# encoding:utf-8
"""
@version: python27
@author: fafa
@site: http://www.phpgao.com
@software: PyCharm Community Edition
@file: chromeserver.py
@time: 2018/7/29 0029 下午 5:24
"""
import time
from selenium import webdriver
class ChromeServerParse(object):
def __init__(self):
# chromedriver的路径
self.excute_path = "D:\\Python\\Python37\\Scripts\\chromedriver.exe"
# 指定chromedriver启动的端口
self.port = 8080
# 指定chromedriver service 启动的参数
self.service_args = ["lang=zh_CN.UTF-8", "--start-maximized", '--disable-infobars']
self.option = webdriver.ChromeOptions()
# 设置字符编码
self.option.add_argument("lang=zh_CN.UTF-8")
# 窗口最大化
self.option.add_argument("start-maximized")
# 隐身模式
self.option.add_argument("incognito")
# 阻止弹出框
self.option.add_argument('disable-infobars')
def start_chromedriver(self):
self.driver = webdriver.Chrome(
executable_path=self.excute_path,
port=self.port,
service_args=self.service_args,
chrome_options=self.option)
driver = self.driver
driver.get("http://www.baidu.com")
time.sleep(5)
if __name__ == '__main__':
ChromeServerParse().start_chromedriver()
转载于:https://www.cnblogs.com/tnyleyon/p/9387997.html