首页 \ 问答 \ python beautifulsoup iframe文档html提取(python beautifulsoup iframe document html extract)

python beautifulsoup iframe文档html提取(python beautifulsoup iframe document html extract)

我正在尝试学习一些美丽的汤,并从一些iFrames中获取一些html数据 - 但迄今为止我还没有取得非常成功。

所以,解析iFrame本身似乎并不是BS4的问题,但我似乎并没有从中获得嵌入的内容 - 无论我做什么。

例如,考虑下面的iFrame(这是我在Chrome开发人员工具上看到的):

<iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="NO"
src="http://www.engineeringmaterials.com/boron/728x90.html "width="728" height="90">
#document <html>....</html></iframe>

其中, <html>...</html>是我有兴趣提取的内容。

但是,当我使用以下BS4代码时:

iFrames=[] # qucik bs4 example
for iframe in soup("iframe"):
    iFrames.append(soup.iframe.extract())

我得到:

<iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="NO" src="http://www.engineeringmaterials.com/boron/728x90.html" width="728" height="90">

换句话说,我得到了其中没有文档<html>...</html>的iFrame。

我尝试了以下几点:

iFrames=[] # qucik bs4 example
iframexx = soup.find_all('iframe')
for iframe in iframexx:
    print iframe.find_all('html')

..但这似乎并没有工作..

所以,我想我的问题是,我如何可靠地从iFrame元素中提取这些文档对象<html>...</html>


I am trying to learn a bit of beautiful soup, and to get some html data out of some iFrames - but I have not been very successful so far.

So, parsing the iFrame in itself does not seem to be a problem with BS4, but I do not seem to get the embedded content from this - whatever I do.

For example, consider the below iFrame (this is what I see on chrome developer tools):

<iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="NO"
src="http://www.engineeringmaterials.com/boron/728x90.html "width="728" height="90">
#document <html>....</html></iframe>

where, <html>...</html> is the content I am interested in extracting.

However, when I use the following BS4 code:

iFrames=[] # qucik bs4 example
for iframe in soup("iframe"):
    iFrames.append(soup.iframe.extract())

I get:

<iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="NO" src="http://www.engineeringmaterials.com/boron/728x90.html" width="728" height="90">

In other words, I get the iFrames without the document <html>...</html> within them.

I tried something along the lines of:

iFrames=[] # qucik bs4 example
iframexx = soup.find_all('iframe')
for iframe in iframexx:
    print iframe.find_all('html')

.. but this does not seem to work..

So, I guess my question is, how do I reliably extract these document objects <html>...</html> from the iFrame elements.


原文:https://stackoverflow.com/questions/23028664
更新时间:2023-12-01 12:12

最满意答案

可以用 gcc呀

相关问答

更多
  • 纯java开发的软件在linux下面也可以应用自如。那么首先就需要配置好linux下的java环境,具体说来,就是配置jdk环境变量。 介绍在linux下配置jdk环境变量的几种常用方法。 首先在linux下安装jdk,如果出现提示权限不够(且root下也提示权限不够),可用#ls -l filename命令查看一下,如果显示类似如: 则表示任何用户都没有可执行权限(即使是root用户)。 解决方法: #chmod a+x filename 这样,安装好后,就可以接下来进行环境变量的配置了。这里给出三种可选 ...
  • eclipse 是 JAVA 写的,全系统支持。 至于你说的那个 pydev ,我想应该也是解释型语言写的,里面不含二进制程序。都能跨平台。
  • 1、安装的过程中会提示你选择相应的软件包来安装,是安装好了的。另外你说的编程环境指的是哪种语言的编程环境?是不是带ui的? 2、没有你说的那种成套的。视频是需要自己找驱动的,QQ也只有QQ for linux(已经不维护了),linux有自己的聊天工具(iptux,pidgin等等)。对于解压缩软件,如果不是解压rar、zip等windows下的压缩格式的话,linux有自己的压缩格式和解压命令,都是自带的。如果要解压windows下的压缩文件,可以安装rar for linux。对于杀毒,linux有很高 ...
  • Linux默认不安装任何编程环境的,图形桌面下的IDE功能也并不是多完善:Linux下最常见的是“开发套件”(真正搞开发的没几个愿意在图形环境的IDE中干活,所以较之于IDE环境,开发套件更合适,这点跟Windows不同)。 安装好开发套件(如gcc),就可以在任何时候从文本控制台调用它的任何命令,而不是先运行一个巨大的编程环境。
  • linux的编程环境[2021-09-19]

    1启动快,不用听硬盘嘎拉嘎拉嘎拉的。 2VIM看代码比较好,不在编辑状态下改不了代码,避免不小心下的误操作;IDE还要启X,linux很多时候要用命令行解决问题,切来切去麻烦;用多了就很习惯,vim红红绿绿的我觉得很好看。 3当然,vim功能很强大,不用多说,比那些免费的IDE要好用。IDE只是提供了一个操作界面,很多IDE都不完善有bug。 4底层编程,用不着IDE,比如即便是微软,写STL等底层库的时候也使用VIM的,你去看一下VC的STL源码,就会发现,那种对齐的风格根本就不是VS的。 Linux下用 ...
  • Linux环境下编程[2023-07-11]

    干这个活还是用 FEDORA 或 GENTOO 好一些
  • 可以用 gcc呀

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)