简体   繁体   English

Python Selenium TypeError:__init__() 需要 1 个位置参数,但给出了 2 个

[英]Python Selenium TypeError: __init__() takes 1 positional argument but 2 were given

My webscraper doesn't work.我的网络爬虫不起作用。 It's giving me this error, "TypeError: init () takes 1 positional argument but 2 were given."它给了我这个错误,“TypeError: init () 需要 1 个位置参数,但给出了 2 个。”

I get that error when I tried opening with Edge, Chrome, and Firefox.当我尝试使用 Edge、Chrome 和 Firefox 打开时出现该错误。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Edge(executable_path="C:\\Users\.......\Python\Python37-32\Lib\site-packages\selenium\edgedriver_win64\msedgedriver.exe")
driver.set_page_load_timeout(30)
driver.get("https://www.udemy.com/topic/python/")
driver.quit()

I looked at example code from other people and it looked the same as what I did.我查看了其他人的示例代码,它看起来和我所做的一样。

Also, the program is in the D drive while the edgedriver_win64 is in the C drive.另外,程序在D盘,edgedriver_win64在C盘。 I don't know if that makes a difference though.我不知道这是否有区别。

Here is the full stack trace:这是完整的堆栈跟踪:

Traceback (most recent call last):
  File "D:\Programs and STEM\Python\Self-Taught Programmer\udemy_course_scraper.py", line 57, in <module>
    scrape.scrape_website()
  File "D:\Programs and STEM\Python\Self-Taught Programmer\udemy_course_scraper.py", line 22, in scrape_website
    driver = webdriver.Edge(executable_path="C:\\Users\Alex\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\edgedriver_win64\msedgedriver.exe")
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 66, in __init__
    desired_capabilities=capabilities)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 402, in _request
    resp = http.request(method, url, body=body, headers=headers)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\request.py", line 72, in request
    **urlopen_kw)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\request.py", line 150, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\poolmanager.py", line 315, in urlopen
    conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\poolmanager.py", line 231, in connection_from_host
    return self.connection_from_context(request_context)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\poolmanager.py", line 244, in connection_from_context
    return self.connection_from_pool_key(pool_key, request_context=request_context)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\poolmanager.py", line 265, in connection_from_pool_key
    pool = self._new_pool(scheme, host, port, request_context=request_context)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\poolmanager.py", line 199, in _new_pool
    return pool_cls(host, port, **request_context)
  File "C:\Users\Alex\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 179, in __init__
    self.pool = self.QueueCls(maxsize)
TypeError: __init__() takes 1 positional argument but 2 were given

I had several issues with the webdriver module finding my exact location of the driver even if it was in the same folder.我在 webdriver 模块中遇到了几个问题,即使它在同一个文件夹中,也无法找到我的驱动程序的确切位置。 This was because if you are running this as a script I believe python by itself checks Its own scripts folder first for any kind of driver executable.这是因为如果您将它作为脚本运行,我相信 python 会首先检查它自己的脚本文件夹中是否有任何类型的驱动程序可执行文件。

I was able to solve this issue by placing the msedgedriver.exe, chromedriver.exe, etc in my python scripts folder.我能够通过将 msedgedriver.exe、chromedriver.exe 等放在我的 python 脚本文件夹中来解决这个问题。 I hope this helps.我希望这有帮助。 Then I was able to run driver = webdriver.Edge()然后我就可以运行driver = webdriver.Edge()

C:\Program Files\Python37\Scripts

I am really confused. 我真的很困惑。 My code looks the same as all of the examples that I have seen but I am still getting this error, "TypeError: init() takes 1 positional argument but 2 were given." 我的代码与我看到的所有示例相同,但仍然出现此错误,“ TypeError:init()接受1个位置参数,但给出了2个位置参数。”

The full stack trace is posted. 完整的堆栈跟踪已发布。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 继承 - 类型错误:__init__() 采用 1 个位置参数,但给出了 4 个 - Python Inheritance - TypeError: __init__() takes 1 positional argument but 4 were given 类型错误:__init__() 需要 1 个位置参数,但给了 2 个 Python - TypeError: __init__() takes 1 positional argument but 2 were given Python TypeError:__ init __()采用1个位置参数,但给出了2个 - TypeError: __init__() takes 1 positional argument but 2 were given TypeError:__init __()接受1个位置参数,但给出了4个 - TypeError: __init__() takes 1 positional argument but 4 were given 解决错误类型错误:__init__() 需要 1 个位置参数,但给出了 2 个 - Solving the error TypeError: __init__() takes 1 positional argument but 2 were given Django 错误 TypeError: __init__() 需要 1 个位置参数,但给出了 2 个 - Django error TypeError: __init__() takes 1 positional argument but 2 were given Pytorch:[TypeError: __init__() 接受 1 个位置参数,但给出了 2 个] - Pytorch: [TypeError: __init__() takes 1 positional argument but 2 were given] TypeError at:/ __init __()接受1个位置参数,但给出了2个 - TypeError at : / __init__() takes 1 positional argument but 2 were given 类型错误:__init__() 需要 1 个位置参数,但给出了 2 个(无继承) - TypeError: __init__() takes 1 positional argument but 2 were given (No Inheritence) TypeError: __init__() 接受 1 个位置参数,但给出了 3 个 - TypeError: __init__() takes 1 positional argument but 3 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM