How to scrape websites when cURL and allow_url_fopen is disabled

I know the question regarding PHP web page scrapers has been asked time and time and using this, I discovered SimpleHTMLDOM. After working seamlessly on my local server, I uploaded everything to my online server only to find out something wasn’t working right. A quick look at the FAQ lead me to this. I’m currently using a free hosting service so edit any php.ini settings. So using the FAQ’s suggestion, I tried using cURL, only to find out that this too is turned off by my hosting service. Are there any other simple solutions to scrape contents of a of another web page without the use or cURL or SimpleHTMLDOM?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

If cURL and allow_url_fopen are not enabled you can try to fetch the content via

  • fsockopen — Open Internet or Unix domain socket connection

In other words, you have to do HTTP Requests manually. See the example in the manual for how to do a GET Request. The returned content can then be further processed. If sockets are enabled, you can also use any third party lib utilitzing them, for instance Zend_Http_Client.

On a sidenote, check out Best Methods to Parse HTML for alternatives to SimpleHTMLDom.

Solution 2

cURL is a specialty API. It’s not the http library it’s often made out to be, but a generic data transfer library for FTP,SFTP,SCP,HTTP PUT,SMTP,TELNET,etc. If you want to use just HTTP, there is an according PEAR library for that. Or check if your PHP version has the official http extension enabled.
For scraping try phpQuery or querypath. Both come with builtin http support.

Solution 3

Here’s a simple way to grab images when allow_url_fopen is set to false, without studying up on estoteric tools.

Create a web page on your dev environment that loads all the images you’re scraping. You can then use your browser to save the images. File -> "Save Page As".

This is handy if you need a one time solution for downloading a bunch of images from a remote server that has allow_url_fopen set to 0.

This worked for me after file_get_contents and curl failed.

Solution 4

file_get_contents() is the simplest method to grab a page without installing extra libraries.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply