python启动谷歌浏览器(怎么用python启动谷歌浏览器)

大家好,今天来为大家解答python启动谷歌浏览器这个问题的一些问题点,包括怎么用python启动谷歌浏览器也一样很多人还不知道,因此呢,今天就来为大家分析分析,现在让我们一起来看看吧!如果解决了您的问题,还望您关注下本站哦,谢谢~

python启动谷歌浏览器(怎么用python启动谷歌浏览器)

本文目录

  1. python可以用自动化打不开浏览器
  2. python调用微信内置浏览器
  3. 如何用声音来操控IE浏览器及语音识别引擎的使用

一、python可以用自动化打不开浏览器

需要下载安装geckodriver,然后将其加入环境变量.

selenium.common.exceptions.WebDriverException: Message:'geckodriver' executable needs to be in PATH.

此版本执行需要驱动:geckodriver

可以去网址这里下载最新的版本。

然后将文件夹解压到C:\geckodriver处,再增加在电脑设置环境变量,如下图所示

然后在创建Firefox的时候设置执行路径

browser= webdriver.Firefox(executable_path='C:\geckodriver\geckodriver.exe')

Traceback(most recent call last): File"C:\learnplace\python_webdevelop_testdriver\functional_tests.py", line 10, in<module>

browser= webdriver.Firefox() File"C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__ self.service.start() File"C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start

os.path.basename(self.path), self.start_error_message)

selenium.common.exceptions.WebDriverException: Message:'geckodriver' executable needs to be in PATH.

Exception AttributeError:"'Service' object has no attribute'process'" in<bound method Service.__del__ of<selenium.webdriver.firefox.service.Service object at 0x00000000030E7CF8>> ignored

Traceback(most recent call last): File"C:\learnplace\python_webdevelop_testdriver\functional_tests.py", line 10, in<module>

browser= webdriver.Firefox(executable_path='C:\geckodriver\geckodriver.exe') File"C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__

keep_alive=True) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__ self.start_session(desired_capabilities, browser_profile) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session

response= self.execute(Command.NEW_SESSION, capabilities) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute

self.error_handler.check_response(response) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

需要将binary的浏览器路径添加以下

from selenium import webdriverfrom selenium.webdriver.firefox.firefox_binary import FirefoxBinary# browser= webdriver.Firefox(# firefox_binary='C:\Program Files(x86)\Mozilla Firefox')# browser.get(';)# assert'Django' in browser.titlebinary= FirefoxBinary(r'C:\Program Files(x86)\Mozilla Firefox\firefox.exe')

browser= webdriver.Firefox(firefox_binary=binary)

browser.get(';)

Traceback(most recent call last): File"C:\learnplace\python_webdevelop_testdriver\functional_tests.py", line 18, in<module>

browser= webdriver.Firefox(firefox_binary=binary) File"C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__

keep_alive=True) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__ self.start_session(desired_capabilities, browser_profile) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session

response= self.execute(Command.NEW_SESSION, capabilities) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute

self.error_handler.check_response(response) File"C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3

以上问题只要更新firefox到47版本就可以了。终于解决了。。

self.browser= webdriver.PhantomJS(executable_path=r'C:\phantomjs\bin\phantomjs.exe')

二、python调用微信内置浏览器

1、首先F12或者右键审查元素进入开发者模式,点击Emulation。

2、其次点击Network,把Spoofuseragent改成Other,并把下面的带复制进去,有三句。

3、然后回车然后刷新页面即可。Python由荷兰数学和计算机科学研究学会的吉多·范罗苏姆于1990年代初设计,作为一门叫做ABC语言的替代品。Python提供了高效的高级数据结构,还能简单有效地面向对象编程。

三、如何用声音来操控IE浏览器及语音识别引擎的使用

最近做字幕的时候发现一个通过声音控制IE浏览器的方法。本来是要制作字幕的,后来想想如果纯手工制作字幕的话那么效率肯定非常低,做为程序员,本能的想到了让计算机来帮忙。做字幕就是从声音识别出文字,然后在校对时间轴。很机械化的操作,非常适合计算机的来做。通过搜索很快找到了解决方案。使用Microsoft Speech SDK+Python+PythonWin。虽然微软的语音识别引擎已经很强大了,但是要用它来制作字幕还有很长的路要走。字幕做不成了,不过用它来操控浏览器还是错错有余的。发现使用语音功能操作IE浏览器还是非常方便,只要设置好语句,IE浏览器就可以自动进行相关的操作。

下面是我已经实现的一些功能。(=符号前面是你要说的话,后面是浏览器执行的操作)

“显示浏览器”=打开浏览器,“谷歌”=进入谷歌的页面,“百度”=进入百度的页面,“优酷”=进入优酷的页面等等,“后退”=返回上一个页面,“最大化”=最大化浏览器,“下拉”=下拉网页,“上拉”=上拉网页,“放大”=放大网页,“缩小”=缩小网页,“关闭浏览器”=关闭浏览器。

1.从微软官网下载SpeechSDK51.exe和SpeechSDK51LangPack.exe

   2.下载Python2.6+PythonWin+wxPython和启动语音识别的脚本文件。从这里打包下载。

3.安装SpeechSDK51.exe,SpeechSDK51LangPack.exe

4.安装Python2.6,PythonWin,wxPython

5.运行开始菜单-所有程序-Python2.6— PythonWin,选择Tools- COM MakePy utility- Microsoft Speech Object Library 5.0

6.在控制面板的语音里面,在语言里选Microsoft Simplified Chinese Recognizer,在语音选择里选Microsoft Simplified Chinese

   环境搭建完成,运行SpeechGui.py脚本就可以来用声音操控浏览器。不过由于Python+PythonWin的强大威力,不单单只有IE浏览器可以进行该操作,只要软件能够支持com的应用就都可以显示语音操控,比如微软的Windows Media Player,Word,Excel等软件。强烈建议大家自己手动去发掘和制作更多有意思的功能。

好了,关于python启动谷歌浏览器和怎么用python启动谷歌浏览器的问题到这里结束啦,希望可以解决您的问题哈!

声明:信息资讯网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,版权归原作者东方体育日报所有。若您的权利被侵害,请联系 删除。

本文链接:http://www.gdxhedu.com/news/103882.html