echo file_get_contents('
https://www.blackhatworld.com');
is all you need bro
That's a good example of
what not to do, lol.
Hello everyone!
I am student and I am learning PHP and Java, I've already know them at some good point. I would like to start with web-scraping so I would like to hear some tips and suggestions from you. What is the best way to start with scraping? What tools are you using? Are you making custom scripts or you are using some scraping software?
How should I start?
It depends on your experience level with PHP and Java, your understanding of HTTP requests/responses, and HTML.
If you're using PHP, definitely opt for cURL instead of
file_get_contents. PHP's cURL implementation is fairly easy to learn. If you already understand HTTP, it's a breeze. Then for extracting data, you can use DOM if you prefer object-oriented programming (if you like Java, you probably love OOP). If you prefer procedural programming, go with regex. Regardless of your preference, you should consider the project at hand and what would work better.
If you're using Java, there's more setup and crap to deal with. But it's well worth it if you're setting up a program you're using often; it's easy to thread, and you can throw the .jar on a VPS very quickly and easily.
All of this assumes you are scraping a site that doesn't heavily rely on Javascript to generate the content you want to scrape. If that's the case, see some of the other responses for JS engines. Though if you investigate the site to scrape, more likely than not it's just an AJAX request that returns easily readable JSON. Then you can skip getting the main page together.
The best thing to do is just dive in. If you have no practical use for scraping right now, make something up. For example, try scraping phone numbers/names off YellowPages.
Best of luck!