MENU

烘焙 - 计算机 - 撸串

这就是我生活的全部 \/n \/n \/n

记录selenium + chrome的一些配置

chrome_options = webdriver.ChromeOptions()
        if visible == 0:
            chrome_options.add_argument('--headless')  # 无头浏览器
        # option.add_argument("--auto-open-devtools-for-tabs") #打开devtools
        # chrome_options.add_argument('--disable-extensions')  # 禁用拓展
        # chrome_options.add_argument('--profile-directory=Default')  # 自定义配置文件
        # chrome_options.add_argument('--incognito')  # 让浏览器直接以隐身模式启动
        # chrome_options.add_argument('--disable-plugins-discovery')
        # chrome_options.add_argument('--disable-logging')  # 禁用日志生成
        # chrome_options.add_argument('--disable-gpu')  # 关闭GPU加速
        # chrome_options.add_argument('--no-sandbox')  # 取消沙盒模式
        # chrome_options.add_argument('--single-process')  # 单进程运行
        chrome_options.add_argument('--disable-dev-shm-usage')  # docker部署时分配空间
        chrome_options.add_argument('user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"')
        chrome_options.add_argument('blink-settings=imagesEnabled=False')  # 无图片加载

        chrome_options.add_experimental_option('useAutomationExtension', False)  # 解决软件正在收到自动化检测
        chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
        chrome_options.add_argument("--disable-blink-features=AutomationControlled")  # 去掉了webdriver痕迹
        if proxies:
            chrome_options.add_argument(f'--proxy-server=socks5://47.241.106.251:1080')
            # proxyauth_plugin_path = create_proxyauth_extension(
            #     proxy_host=proxies.split("@")[1].split(':')[0],
            #     proxy_port=proxies.split(':')[-1],
            #     proxy_username=proxies.split("//")[1].split(':')[0],
            #     proxy_password=proxies.split(":")[2].split('@')[0]
            # )
            # chrome_options.add_extension(proxyauth_plugin_path)

        filepath = get_root_path() + self._get_driver_path()
        self.driver = webdriver.Chrome(executable_path=filepath, chrome_options=chrome_options)
        self.driver.set_page_load_timeout(30)  # 浏览器页面加载超时时间
        self.driver.set_script_timeout(10)
        self.driver.implicitly_wait(10)

        injected_javascript = '''
            // overwrite the `languages` property to use a custom getter
            Object.defineProperty(navigator, "languages", {
              get: function() {
                return ["zh-CN","zh","zh-TW","en-US","en"];
              }
            });
            // Overwrite the `plugins` property to use a custom getter.
            Object.defineProperty(navigator, 'plugins', {
              get: () => [1, 2, 3, 4, 5],
            });
            // Pass the Webdriver test
            Object.defineProperty(navigator, 'webdriver', {
              get: () => false,
            });
            // Pass the Chrome Test.
            // We can mock this in as much depth as we need for the test.
            window.navigator.chrome = {
              runtime: {},
              // etc.
            };
            // Pass the Permissions Test.
            const originalQuery = window.navigator.permissions.query;
            window.navigator.permissions.query = (parameters) => (
              parameters.name === 'notifications' ?
                Promise.resolve({ state: Notification.permission }) :
                originalQuery(parameters)
            );

            '''
        self.driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
            "source": injected_javascript
        })
        self.driver.maximize_window()

关于uwsgi启动Flask的py程序,报错ModuleNotFoundError: No module named 'app'

uwsgin.jpg
先简单介绍下uwsgi的几个日志文件,这有助于排查各类问题。
据我观察和我理解的,uwsgin提供的日志文件有这几个:
1.web空间目录下的uwsgin.log,这个会记录启动过程发生的日志,在启动过程中的报错可以到这里查看。
2.web空间目录下的./logs/error.log,这是访问过程中uwsgin将请求转换成程序处理,这个过程出现的错误,会出现在这里。
3.web空间目录下的./logs/access.log,uwsgin转化的访问日志。

Read More

CentOS7以上防火墙(firewalld)使用

CentOS7以上系统都采用firewalld感念。其底层仍然是iptables.
firewalld基本使用
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld

Read More