Is it possible to extract content from a website using Curl?If yes then how?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Curl is simply a library to make url calls. You can use it to POST to a url or GET which is probably what you want (as well as control many other things). You can also do this using file_get_contents and will normally be easier if you don’t need the extra control that CURL can give you. This will simply give the web sites content, to extract you will want to use an html parser (not regexes (unless you are 100% certain of the format (but not really even then))) and I would suggest simple_dom.
For example $html = file_get_contents(“http://www.google.com”); will put the html of the google home page into the $html variable and then it is upto you to do with it as you will. The main times I use CURL are when I want to pretend my server is a browser (it lets you put your own user agent string), when I want to pull many sites concurrently, or when I need to POAST rather than GET… but of course it can do many other things as well.