【发布时间】:2011-01-09 20:20:40
【问题描述】:
我需要 html 页面的内容,但如果 html 页面包含 iframe 元素,我也需要 iframe 内容。 (在 Python 中) 是否可以使用 python 函数加载所有内容?
【问题讨论】:
-
请查看@Martijn Pieters 对此问题的回答stackoverflow.com/questions/23028664/…。这可能会对您有所帮助。
我需要 html 页面的内容,但如果 html 页面包含 iframe 元素,我也需要 iframe 内容。 (在 Python 中) 是否可以使用 python 函数加载所有内容?
【问题讨论】:
尝试使用BeautifulSoup,其中supports iframes out of the box。
代码 sn-p (full code here):
import re
from BeautifulSoup import BeautifulSoup, Comment
...
for iframe in mosoup("iframe"):
mosoup.iframe.extract()
更新:链接到代码的当前位置(现在在 github 中)。
【讨论】: