pandas groupby 对象,组合和绘图

切换到 iFrame 时出现错误


AttributeError: 'WebDriver' 对象没有属性 'driver'


这个错误的解决方案是什么?我不确定为什么...


driver = webdriver.Firefox()



url = ''


driver.get(url)

while True:

    iframe = driver.find_element_by_xpath('//iframe[@src="/pages/mediator-search"]')

    driver.driver.switch_to.frame(iframe)


    WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//a[@class="mediator-name"]')))

    

    response = Selector(text=driver.page_source)

    agents = response.xpath('//a[@class="mediator-name"]')

    for agent in agents:

        outFile =  open("data.csv",'a+',newline="",encoding='utf-8')

        writer = csv.writer(outFile)

        link = agent.xpath('.//@href').get()

        vals = [link]

        writer.writerow(vals)

        outFile.close()

    

    try:

        next_page = driver.find_element_by_xpath('//a[contains(text(), "›")]')

        if next_page:

            next_page.click()

    except:

        break

还需要进行以下导入

from selenium import webdriver


from selenium.webdriver.support.ui import WebDriverWait


from selenium.webdriver.common.by import By


from selenium.webdriver.support import expected_conditions as EC


from selenium.common.exceptions import TimeoutException


from selenium.webdriver.support.ui import Select


from selenium.webdriver.common.action_chains import ActionChains


from selenium.webdriver.common.keys import Keys


回首忆惘然
浏览 175回答 1
1回答

富国沪深

driver.driver.switch_to.frame(iframe)- 在这里更正.. :)。它应该是driver.switch_to.frame(iframe)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python