0

What Im trying to do is use PHP to scrape a website of a url I enter into a parameter.

I want the whole raw source code.. But thats not all..

I want it then saved into an html page, and onto the local server of the php script.

Is there a Easy Snippet for this? or can someone easily write me up a code?

For example

I want to scrape http://google.com

So for instance, mysite.com/scrape.php?url=http://google.com

I want it to save the front page of google into http://mysite.com/scraped/google.com.html

2
  • By scrape you mean download? Commented Nov 24, 2012 at 6:26
  • How about looking into the documentation for file_get_contents() and file_put_contents() Commented Nov 24, 2012 at 6:26

1 Answer 1

2

Here's a script that will save the contents of the specified url into a file named scraped.html:

if (isset($_GET['url'])):
   $contents = file_get_contents($_GET['url']);
   file_put_contents('scraped.html', $contents);
endif;

To use a url in the call to file_get_contents() you must enable allow_url_fopen in your php.ini file.

Of course this will only save the actual source of the requested url and not any other resources, such as images, scripts and stylesheets.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.