Python 3.x I';m运行基于Selenium的代码时出现名称错误
我正在使用Selenium web驱动程序进行一个项目。预期的结果是它应该打开google.com。 这是我得到的错误Python 3.x I';m运行基于Selenium的代码时出现名称错误,python-3.x,selenium,selenium-webdriver,nameerror,Python 3.x,Selenium,Selenium Webdriver,Nameerror,我正在使用Selenium web驱动程序进行一个项目。预期的结果是它应该打开google.com。 这是我得到的错误 C:\Users\Admin\PycharmProjects\Rohan\venv\Scripts\python.exe "C:/Users/Admin/Rohan_Python/Selenium Web Driver.py" Traceback (most recent call last): File "C:\Users\Admin\Roha
C:\Users\Admin\PycharmProjects\Rohan\venv\Scripts\python.exe
"C:/Users/Admin/Rohan_Python/Selenium Web Driver.py"
Traceback (most recent call last):
File "C:\Users\Admin\Rohan_Python\Selenium Web Driver.py", line 8, in <module>
self.driver.get(url="https://www.google.com/")
NameError: name 'self' is not defined
请帮帮我,给我解决办法。谢谢 1检查缩进和空行。按照惯例,缩进应使用4个空格和2个空行:
from selenium import webdriver
class Info:
def __init__(self):
self.driver = webdriver.Chrome(executable_path='your path')
查看此处了解有关init的更多信息
有关缩进检查的更多详细信息,请参见:
下一步,还要修改代码。别忘了缩进
def get_info(self, query):
self.query = query
self.driver.get(url="https://www.google.com/")
看起来您在缩进方面有问题
def get_info(self, query):
self.query = query
self.driver.get(url="https://www.google.com/")