python-3.x - webbrowser.open() 在输入后面添加 /
问题描述
我正在尝试使用语音识别搜索某些内容,但该命令被解释为 URL,它将在命令之后添加 /。斜线使单词成为 URL。我不想要一个 URL,而只是搜索栏上的一个普通单词。
例如:我:“搜索动物”
结果 - 动物/(无法访问站点)
有没有办法解决这个问题?
代码如下:
elif 'google' in command or 'search' in command:
talk("Googling.")
command = command.replace('google','')
command = command.replace('search','')
chrome_path = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
webbrowser.register('edge', None , webbrowser.BackgroundBrowser(chrome_path))
webbrowser.get('edge').open_new_tab(command)
解决方案
webbrowser.open_new_tab()需要一个 URL。
添加要查找查询数据的搜索引擎(命令)。
webbrowser.get('edge').open_new_tab('https://google.com/search?q={}'.format(command))
webbrowser 模块启动您的浏览器并在其中打开指定的网页。
推荐阅读
- sql - 如何查询今天前60天的记录
- node.js - 将 MERN 部署到 AWS EC2 时无法获取“/”路由和 500 内部服务器错误
- php - ldap 记录认证失败
- java - Java Spring Jackson - 处理程序调度失败错误
- itext - 使用 iText7 和 htmlpdf 设置应用程序/创建者元数据
- reactjs - 使用 JSX 的 useState Hook
- php - 在 Docker PHP 容器中运行 Rsync
- terraform - terraform 中的 GCE 关闭脚本
- php - ContactForm7 在提交 WordPress Woocommerce 网站时显示 POST 和 GET 错误
- c# - 如何获取所有显示器联合中的矩形,该区域不包含在显示器区域中