Posted on Thursday 8th of March 2007 at 12:07 in Tutorials

Scraping website content with PHP using Curl

I've been building a side project that just so happens to need this functionality so thought I'd document it on the site as I go.

The function below takes a URL and connects to it and returns all the contents.



How do I use it?
See the code below for an example implementation of the function.



$content will then become the full HTML of the page, so outputting it will replicate the page in it's entirety. Do with it what you will.

 

Enjoy this article? Why not subscribe to the full RSS feed?

Add Your Comments








Comments

Showing most recent 4 of 4 comments

Form broke the code I posted.

inside the two forward slashes you would put

something like this

< a h r e f = ' ( . * ? ) ' >

hopefully the form doesnt break this. if it doesnt then just remove spaces.
try preg_match

$content = get_content("http://www.somewebsite.com");
preg_match("//",$content,$output);

echo $output[1];

// That will output the first url it comes across within an a href tag.
You can also use preg_match_all to grab them all and lots of other things.
thats fine but how can parse that to get only required contents and save them...
thx
http://apexvideo.blogspot.com
Any articles or snippets on ow to refine the $content and get only ceratin information from it?

Subscribe to the RSS Feed

Stay up to date with Seopher.com by subscribing to the RSS feed, either in your browser or subscribe via email using the form below

Updates by Email

By subscribing by email you’re also subscribing to the Seopher.com newsletter; a periodical email outlining new reviews, competitions and other subscriber-only content

  • 125x125 banner only $50 pcm
  • make money online with t3leads
Want to give your product/website exposure?

Paying for a featured review is a great way to give your product, service or website exposure. For as little as $50 you can have a full review on the site forever.

Advertising Bundle! Review + Banner = $70

To kick start the new improved Seopher.com, buy a review and get a 125x125 advert half price. Your banner gets displayed on over 450 pages for a full month.