简体   繁体   English

如何抓取html + css

[英]How to scrape html+css

What is a pure PHP solution for scraping HTML along with their CSS styles? 什么是纯HTML以及HTML的CSS样式抓取解决方案?

For example, scraping this page 例如,抓取此页面

<!doctype html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<div id="success" class="alert alert-success" role="alert" style="font-size:30px">Success</div>

where id=success would return 其中id = success将返回

<div style="color: rgb(60, 118, 61); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 30px; line-height: 42.8571434020996px; background-color: rgb(223, 240, 216);">Success</div>

as if I had manually copied that part of the page. 就像我手动复制了页面的那一部分一样。

If I undestood correctly, you want to add an inline-style set to the id "sucess" with PHP. 如果我没有正确理解,您想使用PHP将内联样式集添加到ID“成功”中。

You could do something with: 您可以执行以下操作:

<?php

    $inlineStyle = "color: rgb(60, 118, 61); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 30px; line-height: 42.8571434020996px; background-color: rgb(223, 240, 216);";

?>

And add it on you HTML tag: 并将其添加到您的HTML标签上:

<div id="success" .... style="<?= $inlineStyle ?>"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM