切換到 iFrame 時(shí)出現(xiàn)錯(cuò)誤AttributeError: 'WebDriver' 對(duì)象沒有屬性 'driver'這個(gè)錯(cuò)誤的解決方案是什么?我不確定為什么...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還需要進(jìn)行以下導(dǎo)入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貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
driver.driver.switch_to.frame(iframe)
- 在這里更正.. :)。它應(yīng)該是driver.switch_to.frame(iframe)
添加回答
舉報(bào)
0/150
提交
取消