_move.htm'; break; case '404': $pre .= $default_pre .= '404.htm'; break; case 'read_404': $pre .= $default_pre .= 'read_404.htm'; break; case 'list_404': $pre .= $default_pre .= 'list_404.htm'; break; default: $pre .= $default_pre .= theme_mode_pre(); break; } if ($config['theme']) { $conffile = APP_PATH . 'view/template/' . $config['theme'] . '/conf.json'; $json = is_file($conffile) ? xn_json_decode(file_get_contents($conffile)) : array(); } !empty($json['installed']) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . ($id ? $id . '_' : '') . $pre; (empty($path_file) || !is_file($path_file)) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . $pre; if (!empty($config['theme_child']) && is_array($config['theme_child'])) { foreach ($config['theme_child'] as $theme) { if (empty($theme) || is_array($theme)) continue; $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . ($id ? $id . '_' : '') . $pre; !is_file($path_file) and $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . $pre; } } !is_file($path_file) and $path_file = APP_PATH . ($dir ? 'plugin/' . $dir . '/view/htm/' : 'view/htm/') . $default_pre; return $path_file; } function theme_mode_pre($type = 0) { global $config; $mode = $config['setting']['website_mode']; $pre = ''; if (1 == $mode) { $pre .= 2 == $type ? 'portal_category.htm' : 'portal.htm'; } elseif (2 == $mode) { $pre .= 2 == $type ? 'flat_category.htm' : 'flat.htm'; } else { $pre .= 2 == $type ? 'index_category.htm' : 'index.htm'; } return $pre; } ?>selenium如何控制已打开浏览器
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

selenium如何控制已打开浏览器

运维笔记admin1浏览0评论

在使用selenium进行Web自动化的时候,部分网站会有验证码、缓存等等原因,需在登录后再进行后续自动化。此时,就需控制在已打开的浏览器,在此,以 Chrome为例进行分析。

1、确定当前浏览器驱动是最新的

http://npm.taobao/mirrors/chromedriver/

下载当前版本对应的驱动进行安装(替换安装目录中的chromedriver.exe)

2、在谷歌浏览器快捷方式>属性>目标中添加:

[--headless] --remote-debugging-port=9222 --user-data-dir="D:\Chrome"

1)对于-user-data-dir标记,指定创建新Chrome配置文件的目录。它是为了确保在单独的配置文件中启动chrome,不会污染你的默认配置文件

2) 不要忘了在环境变量中PATH里将chrome的路径添加进去

3、配置好浏览器后,点击快捷方式,打开浏览器,前往百度网址www.baidu

4、编辑python文件

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

chrome_options = Options()

chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

chrome_driver = r"C:\Users\dell\AppData\Local\Google\Chrome\Application\chromedriver.exe"

driver = webdriver.Chrome(chrome_driver, options=chrome_options)

print(driver.title)

1)运行后可打印出百度网址的标题

2)可参考以上操作控制其他页面

参考原文: https://wwwblogs/lovealways/p/9813059.html

发布评论

评论列表(0)

  1. 暂无评论