切换到 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 webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.common.exceptions import TimeoutExceptionfrom selenium.webdriver.support.ui import Selectfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.keys import Keys
1 回答
富国沪深
TA贡献1790条经验 获得超9个赞
driver.driver.switch_to.frame(iframe)
- 在这里更正.. :)。它应该是driver.switch_to.frame(iframe)
添加回答
举报
0/150
提交
取消