在Python中获取iframe内容
我需要获取一个网页的内容,但如果这个网页里面有一个iframe元素,我也需要获取这个iframe里的内容。(用Python来做) 请问有没有办法用一个Python函数把所有内容都加载出来呢?
1 个回答
3
试试使用 BeautifulSoup,这个工具 可以直接支持iframe。
代码片段(完整代码在这里):
import re
from BeautifulSoup import BeautifulSoup, Comment
...
for iframe in mosoup("iframe"):
mosoup.iframe.extract()
更新:链接到代码的当前地址(现在在github上)。