是否有可能从HTML中提取内联CSS? [英] Is it possible to extract inline CSS from HTML?

查看:156
本文介绍了是否有可能从HTML中提取内联CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 http://simplehtmldom.sourceforge.net/manual.htm ,是否有可能提取HTML文件的内联CSS?



这个解析器如果是纯html,假设(只是纠正我,如果我错了)它不能解析CSS标签。有没有其他方法可以在HTML文件中提取内联CSS?

解决方案

如果您确实需要使用simplehtmldom来解压缩:




对于

 <风格> 
...
< / style>

使用:

  $ css = $ html-> find('style') - > innertext; 






For

 < div style =background:blue; color:white;>< / div> 

使用:

  $ css = $ html-> find('div [style]') - > style; 






如果有多个 div with style atribute或多个< style> ,您可以使用一个 foreach 在它们之间循环。


Using http://simplehtmldom.sourceforge.net/manual.htm, is it possible to extract the inline CSS of a HTML file?

This parser if pure html, assuming (just correct me if I'm wrong) it can't parse CSS tags.Is there any other way to extract inline CSS in the html file?

解决方案

If you really need to use simplehtmldom to extract this :


For

<style>
...
</style>

Use :

$css = $html->find('style')->innertext;


For

<div style="background:blue; color:white;"></div>

Use :

$css = $html->find('div[style]')->style;


If there's more than one div with style atribute or more than one <style>, you can use a foreach to loop between them.

这篇关于是否有可能从HTML中提取内联CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆