简体   繁体   English

TypeError: init() 需要 2 个位置 arguments 但给出了 3 个

[英]TypeError: init() takes 2 positional arguments but 3 were given

def main():
    sc = scraper.Scraper()
    sc.load_url()
    for _ in range(SCROLL_RANGE):
        time.sleep(1)
        sc.scroll_down()
    time.sleep(5)
    sc.read_data()
    print(sc.get_hrefs())
    sc.get_info('https://www.carwale.com' + '/used/cars-in-delhi/renault-kwid-2019-d2328551/?slot=4&rk=4&isP=true')
    time.sleep(3000)
    sc.load_url()
    print("Hello Script")

if __name__ == '__main__':
    main()

Error:错误:

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/webscraper/main.py", line 21, in <module>
    main()


  File "C:/Users/PycharmProjects/webscraper/main.py", line 15, in main
    sc.get_info('https://www.carwale.com' + '/used/cars-in-delhi/renault-kwid-2019-d2328551/?slot=4&rk=4&isP=true')


  File "C:\Users\PycharmProjects\webscraper\scraper.py", line 29, in get_info
    cf = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(By.CSS_SELECTOR, '#overview > div > ul'))


TypeError: __init__() takes 2 positional arguments but 3 were given
class Scraper:
def __init__(self):
    self.driver = webdriver.Chrome(r'C:\Users\gkhat\Downloads\chromedriver.exe')
    self.url = "http://www.carwale.com/used/cars-for-sale/#sc=-1&so=-1&pn=1"
    self.hrefs = []
def get_hrefs(self):
    return self.hrefs
def load_url(self):
    self.driver.get(self.url)
def scroll_down(self):
    self.driver.execute_script('window.scrollTo(0, document.body.scrollHeight)')
def read_data(self):
    main = self.driver.find_element_by_xpath('/html/body/div[12]/form/section[2]/div[1]/div[4]/div[1]/div[3]/div[2]')
    soup = bs(main.get_attribute("innerHTML"), "html.parser")
    for elem in soup.findAll('h2', {'class': 'card-detail-block__title'}):
        print(elem.a['href'])
        self.hrefs.append(str(elem.a['href']))
def get_info(self, url):
    self.driver.get(url)
    time.sleep(1)
    cf = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located(By.CSS_SELECTOR, '#overview > div > ul'))
    soup = bs(cf.get_attribute("innerHTML"), "html.parser")
    for li in soup.find_all('li'):
        print(li.text)
cf = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#overview > div > ul')))

you have to pass a tuple to the EC.presence of element你必须将一个元组传递给元素的 EC.presence

暂无
暂无

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

相关问题 TypeError:init()接受0个位置参数,但给出了5个 - TypeError: init() takes 0 positional arguments but 5 were given TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given - TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given python super:TypeError:__init __()接受2个位置参数,但给出了3个 - python super :TypeError: __init__() takes 2 positional arguments but 3 were given Money 和 TypeError:__init__() 需要 1 到 2 个位置参数,但给出了 3 个 - Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given 类型错误:__init__() 需要 2 个位置参数,但给出了 4 个 - TypeError: __init__() takes 2 positional arguments but 4 were given 多个 inheritance,TypeError: __init__() 需要 2 个位置 arguments 但给出了 3 个 - multiple inheritance, TypeError: __init__() takes 2 positional arguments but 3 were given 类型错误:__init__() 需要 3 个位置参数,但给出了 4 个 - TypeError: __init__() takes 3 positional arguments but 4 were given TypeError:__init __()接受4个位置参数,但给出了5个 - TypeError: __init__() takes 4 positional arguments but 5 were given TypeError: __init__() 接受 2 个位置参数,但在 RFE 中给出了 3 个 - TypeError: __init__() takes 2 positional arguments but 3 were given in RFE 继承 TypeError: __init__() 接受 1 到 2 个位置参数,但给出了 8 个 - inheritance TypeError: __init__() takes from 1 to 2 positional arguments but 8 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM