难以将Selenium指向正确的iFrame[python]

难以将Selenium指向正确的iFrame[python],python,selenium,mechanicalturk,Python,Selenium,Mechanicalturk,我正在尝试让我的selenium脚本从MTurk热门下载一个图像。我的脚本可以登录到MTurk,进入“接受新的点击”页面,找到我想要从中获取图像的点击,但是我无法将其指向我想要的特定图像。我已经尝试了selenium文档中列出的每一种方法(通过\u class\u name、通过\u id、通过\u element查找\u element),等等,但我无法找到它 到目前为止,我所拥有的: from selenium import webdriver from bs4 import Beautif

我正在尝试让我的selenium脚本从MTurk热门下载一个图像。我的脚本可以登录到MTurk,进入“接受新的点击”页面,找到我想要从中获取图像的点击,但是我无法将其指向我想要的特定图像。我已经尝试了selenium文档中列出的每一种方法
(通过\u class\u name、通过\u id、通过\u element查找\u element)
,等等,但我无法找到它

到目前为止,我所拥有的:

from selenium import webdriver
from bs4 import BeautifulSoup

driver = webdriver.Firefox()

driver.get("https://www.mturk.com/mturk/myhits")

elem = driver.find_element_by_id("ap_email")
elem.send_keys('####')
elem = driver.find_element_by_id("ap_password")
elem.send_keys('###')
elem = driver.find_element_by_id("signInSubmit-input")
elem.click()
driver.get("https://www.mturk.com/mturk/previewandaccept?groupId=3ZXRRTK2NDCB5NW5M24C9P2OWG41OF")
hit = driver.switch_to_frame("ExternalQuestionIFrame")
print(hit)
这给了我:

None
我期望的输出: 链接中的HTML
https://backend.ibotta.com/receipt_moderation/50730299/edit?assignmentId=33FBRBDW6OZTOIJ53FZR716JLOQC8N&hitId=3D3B8GE892RAASDPNAMA2D4I3E3P9G&workerId=A1DY4DM16TBFPL&turkSubmitTo=https%3A%2F%2Fwww.mturk.com

我试图访问的元素在页面源代码中称为
ExternalQuestionIFrame
,如下所示:

 </style><iframe height="1000" scrolling="auto" frameborder="0" align="center" src="https://backend.ibotta.com/receipt_moderation/50730299/edit?assignmentId=33FBRBDW6OZTOIJ53FZR716JLOQC8N&amp;hitId=3D3B8GE892RAASDPNAMA2D4I3E3P9G&amp;workerId=A1DY4DM16TBFPL&amp;turkSubmitTo=https%3A%2F%2Fwww.mturk.com" name="ExternalQuestionIFrame"></iframe>


有人能看出我哪里做错了吗?非常感谢您的回复

您不需要切换到iframe来获得它的
src
。只需找到元素并使用
get_attribute()
检索
src
属性值:

frame = driver.find_element_by_name("ExternalQuestionIFrame")
print(frame.get_attribute("src"))

非常感谢你,alecxe!