大宗商品漲價狂潮,通脹風險加劇

laical發表於2022-04-20

近期在供應不足和強勁的市場需求雙雙推動下,大宗商品掀起一輪漲價狂潮。4 月 18 日,美國天然氣、玉米期貨雙雙突破 8 美元,重新整理多年來新高。此外,黃金、原油、工業金屬等商品價格也普遍上漲,原油類大宗商品基金大幅上漲。

大宗商品價格飆升會讓 PPI 高漲,進而傳導到 CPI,加劇通脹問題。此外,不單單是傳統能源,新能源也會存在綠色通脹問題,總體而言,通脹可能會成為一箇中期問題。種種跡象表明美聯儲今年有可能通過多次加息讓利率以控制通脹風險的快速加劇。可以通過爬蟲程式(python語言Selenium框架),配合爬蟲代理IP定期採集相關資訊,及時關注市場變化。

    from selenium import webdriver
    import string
    import zipfile
    # 代理伺服器(產品官網 )
    proxyHost = "t.16yun.cn"
    proxyPort = "3111"
    # 代理驗證資訊
    proxyUser = "username"
    proxyPass = "password"
    def create_proxy_auth_extension(proxy_host, proxy_port,
                                    proxy_username, proxy_password,
                                    scheme='http', plugin_path=None):
        if plugin_path is None:
            plugin_path = r'/tmp/{}_{}@t.16yun.zip'.format(proxy_username, proxy_password)
        manifest_json = """
        {
            "version": "1.0.0",
            "manifest_version": 2,
            "name": "16YUN Proxy",
            "permissions": [
                "proxy",
                "tabs",
                "unlimitedStorage",
                "storage",
                "<all_urls>",
                "webRequest",
                "webRequestBlocking"
            ],
            "background": {
                "scripts": ["background.js"]
            },
            "minimum_chrome_version":"22.0.0"
        }
        """
        background_js = string.Template(
            """
            var config = {
                mode: "fixed_servers",
                rules: {
                    singleProxy: {
                        scheme: "${scheme}",
                        host: "${host}",
                        port: parseInt(${port})
                    },
                    bypassList: ["localhost"]
                }
              };
            chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
            function callbackFn(details) {
                return {
                    authCredentials: {
                        username: "${username}",
                        password: "${password}"
                    }
                };
            }
            chrome.webRequest.onAuthRequired.addListener(
                callbackFn,
                {urls: ["<all_urls>"]},
                ['blocking']
            );
            """
        ).substitute(
            host=proxy_host,
            port=proxy_port,
            username=proxy_username,
            password=proxy_password,
            scheme=scheme,
        )
        print(background_js)
        with zipfile.ZipFile(plugin_path, 'w') as zp:
            zp.writestr("manifest.json", manifest_json)
            zp.writestr("background.js", background_js)
        return plugin_path
    proxy_auth_plugin_path = create_proxy_auth_extension(
        proxy_host=proxyHost,
        proxy_port=proxyPort,
        proxy_username=proxyUser,
        proxy_password=proxyPass)
    option = webdriver.ChromeOptions()
    option.add_argument("--start-maximized")
    # 如報錯 chrome-extensions
    # option.add_argument("--disable-extensions")
    option.add_extension(proxy_auth_plugin_path)
    # 關閉webdriver的一些標誌
    # option.add_experimental_option('excludeSwitches', ['enable-automation'])
    driver = webdriver.Chrome(
        chrome_options=option,
        executable_path="./chromdriver"
    )
    # 修改webdriver get屬性
    # script = '''
    # Object.defineProperty(navigator, 'webdriver', {
    # get: () => undefined
    # })
    # '''
    # driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {"source": script})
    driver.get(")


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946368/viewspace-2887935/,如需轉載,請註明出處,否則將追究法律責任。

相關文章