如何抓取html+css


How to scrape html+css

什么是用于抓取HTML及其CSS样式的纯PHP解决方案?

例如,刮取此页面

<!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>

其中id=成功将返回

<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>

就好像我手动复制了页面的那部分。

如果我不希望正确,您需要使用PHP向id"sucess"添加一个内联样式集。

你可以用做点什么

<?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);";
?>

并将其添加到HTML标签上:

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