0

What is a pure PHP solution for scraping HTML along with their CSS styles?

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

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

user1461607
  • 2,416
  • 1
  • 25
  • 23
  • you could get the html markup, i don't know about CSS though, getting the CSS rule is another thing. what i would do is, get the markup first, get the ID, then parse the CSS separately – Kevin Apr 07 '15 at 04:14
  • It takes a browser to resolve css and html into a single entity. It sounds like you're looking for a [headless browser](http://stackoverflow.com/a/13424762/622391). – Simon MᶜKenzie Apr 07 '15 at 04:30

1 Answers1

0

If I undestood correctly, you want to add an inline-style set to the id "sucess" with PHP.

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:

<div id="success" .... style="<?= $inlineStyle ?>"></div>
Bruno Henrique
  • 757
  • 10
  • 21
  • I don't think you have understood correctly - the OP is trying to [scrape](http://en.wikipedia.org/wiki/Web_scraping) an external site. They don't have access to the source. – Simon MᶜKenzie Apr 07 '15 at 04:29