def get_ie_driver_bak2(): """ https://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy :return: """ PROXY = "47.96.0.157:4444" # Create a copy of desired capabilities object. desired_capabilities = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy( ) # Change the proxy properties of that copy. desired_capabilities['proxy'] = { "httpProxy": PROXY, "ftpProxy": PROXY, "sslProxy": PROXY, "noProxy": None, "proxyType": "MANUAL", "class": "org.openqa.selenium.Proxy", "autodetect": False } LOGGER.info("try to use proxy: %s", PROXY) # you have to use remote, otherwise you'll have to code it yourself in python to # dynamically changing the system proxy preferences driver = webdriver.Remote("http://localhost:4444/wd/hub", desired_capabilities) return driver
def get_all_data_from_cache(order_download_date): """ 从缓存中获取所有商户信息数据 :return: """ try: cache_file_full_path = get_cache_full_path(order_download_date) with open(cache_file_full_path, 'rb') as cache_file: res = pickle.load(cache_file) LOGGER.info("加载商户缓存数据成功") return res except Exception as ex: LOGGER.error("加载商户缓存数据异常,Exception=%s", ex)
def save_all_data_to_cache(order_download_date, res): """ 保存所有信息到缓存 :return: """ if not is_valid_data(res): LOGGER.warn("跳过刷新商户数据缓存,无效的缓存。tip=%s", res.get('tip')) return None try: cache_file_full_path = get_cache_full_path(order_download_date) with open(cache_file_full_path, 'wb') as cache_file: pickle.dump(res, cache_file) LOGGER.info("刷新商户数据缓存成功,tip=%s", res.get('tip')) except Exception as ex: LOGGER.error("刷新商户数据缓存异常,%s", ex)
def refresh_merchant_config(from_front=False): """ 刷新商户状态和配置等 :return: """ LOGGER.info(u"获取商户配置数据") cfgs = get_merchant_config() if can_refresh(from_front): check_status(cfgs) res = list() count = 0 for d in cfgs: res.append(d.to_dict()) if d.status: count += 1 LOGGER.info(u"在线商户:%s", count) record_offline_time(count) return sort_merchant(res)
def get_ie_driver(): """ https://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#proxy-json-object 使用方式:先用正常页面不带代理的,启动多个窗口登录。登录成功后,再切换回代理。 TODO: 需要设置刷新的时候也走代理,本地模式。 服务模式不需要。 :return: """ proxy = get_proxy() driver = None if proxy: prox = Proxy() prox.proxy_type = ProxyType.MANUAL prox.http_proxy = proxy prox.socks_proxy = proxy prox.ssl_proxy = proxy prox.ftp_proxy = proxy LOGGER.info("try to use proxy: %s", proxy) caps = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy() # caps['proxy'] = { # "httpProxy": proxy, # "ftpProxy": proxy, # "sslProxy": proxy, # "socks_proxy": proxy, # "noProxy": None, # "proxyType": "MANUAL", # "autodetect": False # } prox.add_to_capabilities(caps) # caps["proxy"] = {"proxyType": "manual", "httpProxy": proxy} opt = options.Options() opt.use_per_process_proxy = True driver = webdriver.Ie(capabilities=caps, options=opt) else: driver = webdriver.Ie() return driver