• [deleted]

I want to customize a page using file_get_contents

$a=file_get_contents('http://google.com');
echo $a;

or

$a=fopen('http://google.com','r');
$b = stream_get_contents($a);
echo $b;
fclose($a);

I need to know how I can change the front end of the pages I want to display using my own CSS for the file_get_contents!

Thanks for reading,
Phil

    The way you get the information via PHP is irrelevant; CSS works just the same no matter where the HTML came from.

      • [deleted]

      When I try the following it does not work! I'm really stuck on this one!

      <html>
      <head>
      <style type="text/css">
      body
      {
      background-color:#b0c4de;
      }
      </style>
      </head>
      
      <body>
      
      <?php
      $a=fopen('http://shop.ebay.co.uk/any4any1/m.html','r');
      $b = stream_get_contents($a);
      echo $b;
      fclose($a);
      ?>
      
      </body>
      </html>

        the page your loading has its own css, and docutype etc so that's messing everything up and i assume e-bay wouldn't be happy.

          There is a way to replace the css of the page I am grabbing i just dont know what the code would be. Someone out there must know how to do this!?!

          Thanks,
          Phil.

            philipryoung wrote:

            Someone out there must know how to do this!?!

            Yup - don't do it.

            Screen scraping is the absolute worst way you can get data from an external site. If you have permission to use that external site's data, then they most likely provide a way to get the data you need without the HTML markup (RSS/XML feed, REST, public API, etc. etc.).

            If you don't have permission... well then why are we even discussing it? 😉

              I'm pretty sure eBay allow users to grab data from their website, especially my own listings. I know this because of the hundreds of apps and widgets out their that do the same. This is also why I know it is possible, just because eBay doesn't give me an RSS or another alternative for getting data then doesn't mean I shouldn't try it myself.

              Could you tell me what the best way to extract data from a website is instead of only telling me what I'm doing wrong?

                philipryoung wrote:

                I'm pretty sure eBay allow users to grab data from their website

                "Pretty sure" doesn't really cut it. Either you're legally allowed to or you aren't (and remember, ignorance is no excuse).

                philipryoung wrote:

                especially my own listings.

                Not really - you gave away your rights when you posted the listing on eBay:

                eBay User Agreement wrote:

                When you give us content, you grant us a non-exclusive, worldwide, perpetual, irrevocable, royalty-free, sublicensable (through multiple tiers) right to exercise any and all copyright, trademark, publicity, and database rights (but no other rights) you have in the content, in any media known now or in the future.

                philipryoung wrote:

                I know this because of the hundreds of apps and widgets out their that do the same.

                The "same" as in screen-scraping the HTML content of a page? I doubt that. 😉

                philipryoung wrote:

                just because eBay doesn't give me an RSS or another alternative for getting data then doesn't mean I shouldn't try it myself.

                Uh... actually, it does if a) they actually do give you alternative methods for getting the data, and b) if they prohibit other methods of scraping data from their website except for such alternative methods.

                And in fact, eBay does have such a clause in the policies you agreed to abide by:

                eBay User Agreement wrote:

                The sites contain robot exclusion headers. Much of the information on the sites is updated on a real-time basis and is proprietary or is licensed to eBay by our users or third parties. You agree that you will not use any robot, spider, scraper or other automated means to access the sites for any purpose without our express hand written permission.

                philipryoung wrote:

                Could you tell me what the best way to extract data from a website is

                Already did that above.

                philipryoung wrote:

                instead of only telling me what I'm doing wrong?

                shrug Okay fine, you're not "wrong." But since what you're doing violates eBay's user agreement, I'll simply stop posting in your thread.

                  Write a Reply...