【问题标题】:Referencing mytubeid in iframe using Python Selenium使用 Python Selenium 在 iframe 中引用 mytubeid
【发布时间】:2017-07-27 23:53:14
【问题描述】:

mytubeid 标记(如 <iframe src="/portal/corporateEventsCalendarIframe.html" mytubeid="mytube1" width="820" height="1600" frameborder="0"/>)在 iframe 中的作用是什么?

请注意iframe 中没有id 或类似的名称!

如何在代码中引用它?我正在使用 python+selenium+scrapy 来构建一个网页抓取工具。

【问题讨论】:

  • 我认为mytubeidiframe标签下的属性而不是标签

标签: python html selenium iframe scrapy


【解决方案1】:

如果您想使用 selenium 找到这个 iframe,请尝试类似

driver.find_element_by_xpath('//iframe[@mytubeid="mytube1"]').

如需更明确的答案,请提供一些代码和网址。

【讨论】:

  • 感谢@Vlad,它确实帮助我检索了预期的元素,但我正在寻找可以与responsethingy 一起使用的东西。 intended siteiframe 中包含我所需的信息,it 进一步要求我单击 链接 才能到达那里。我的 python+selenium+scrapy 用于数据获取有点迷失了!
  • 为了将一个scrapy响应中的url传递给selenium,你可以使用driver.get(response.url)。之后,您可能需要切换到所需的 iframe driver.switch_to_frame("frameName") 并找到您需要单击的链接。此外,您可以使用 link.get_attribute("href") 从链接中获取 href 属性,并将该 href 传递给 scrapy 或 selenium。不幸的是,没有你的代码,我只能建议。
【解决方案2】:

看看这个:

http://selenium-python.readthedocs.io/locating-elements.html#locating-by-xpath

您可以通过 XPath 定位元素。

来自网站:

使用 XPath 的主要原因之一是您没有合适的 id 或 name 属性来定位您想要定位的元素。

【讨论】:

    猜你喜欢
    • 2021-03-06
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 2015-01-23
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多