【问题标题】:Scraping iframes without source with python使用 python 抓取没有源的 iframe
【发布时间】:2020-05-27 08:35:02
【问题描述】:

我正在尝试从以下 html 文件中抓取 iFrame (id="topic") 的内容:

我尝试使用硒和美丽的汤,但是代码仍然看不到 iFrame 内的元素。

有没有一种有效的方法可以从这里抓取提到的 iFrame 的内容 html 文件(最好不使用硒)?

【问题讨论】:

标签: python selenium web-scraping beautifulsoup python-requests


【解决方案1】:

您需要找到iframe 的网址。

我发现是https://help.aprimo.com/Content/Marketing_Operations_Help/release_notes/release_notes_current_release_activity.html

那么所有的代码就是:

import requests
from bs4 import BeautifulSoup

url = "https://help.aprimo.com/Content/Marketing_Operations_Help/release_notes/release_notes_current_release_activity.html"
response = requests.get(url=url).text
soup = BeautifulSoup(response)
# Then it is your work.

但我还是建议你使用selenium。 你可以使用driver.switch_to.frame("topic") 切换到这个iframe 然后做你想做的事。

【讨论】:

  • 行得通,谢谢!还有一个问题,您在哪里找到 iFrame 网址?我试图寻找它,但我没有设法找到它。
  • @TheBvrtosz 你可以使用Chrome控制台,执行我发的图片中的js代码。
猜你喜欢
  • 1970-01-01
  • 2022-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多