SyntaxError:IPython中的execute_path语法无效 [英] SyntaxError: invalid syntax with executable_path in ipython

查看:142
本文介绍了SyntaxError:IPython中的execute_path语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium Web驱动程序在Python中进行作业.我收到语法错误.我正在使用google colab和Python 3.

I am using selenium web driver for an assignment in Python. I am getting a syntax error. I am using google colab and Python 3.

这是我的代码

import time
from selenium import webdriver
driver = webdriver.Chrome (r "C:\Users\Anisha\Downloads\chromedriver.exe")
time.sleep(20)

我遇到错误

File "<ipython-input-28-7654fa692ce2>", line 1
driver = webdriver.Chrome (r "C:\Users\Anisha\Downloads\chromedriver.exe")
                                                                        ^
SyntaxError: invalid syntax

请帮助我不要误解我的意思.

Please help I am not getting where I am wrong.

推荐答案

如果要在 Windows操作系统中传递 chromedriver 二进制文件的位置,则必须:

If you intend to pass the location of the chromedriver binary in Windows OS you have to:

  • 通过 Key / Value 对提及 chromedriver 二进制文件的绝对位置 execute_path ,您还必须添加二进制扩展名,即 .exe .
  • 在提及 chromedriver 二进制文件的绝对位置时,您必须使用单个前斜杠,即 \ 和原始字符 r 开关,否则您必须转义反斜杠 \\ .
  • 您的有效代码行将是:

  • While mentioning the absolute location of the chromedriver binary through the Key / Value pair of executable_path you have to add the binary extension as as well i.e. .exe.
  • While mentioning the absolute location of the chromedriver binary you have to either use the single front slash i.e. \ along with the raw r switch or you have to escape the back slash \\.
  • Your effective line of code will be :

  • 采用以下格式之一:

  • Either in this format:

driver = webdriver.Chrome(executable_path="C:\\Users\\Anisha\\Downloads\\chromedriver.exe")

  • 或采用以下格式:

  • Or in this format:

    driver = webdriver.Chrome(executable_path=r'C:\Users\Anisha\Downloads\chromedriver.exe')
    

  • 这篇关于SyntaxError:IPython中的execute_path语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆