Jump to content

Opening an array of HTMLs using Curl Init


xZenjix

Recommended Posts

<html>
<head>
<title>Testing</title>
</head>

<body>
<?php
$config = parse_ini_file("config.ini",1);
$email = $config['Email'];
$host = $config['Host'];


print_r ($host);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $host);


curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec ($ch);


$fp = fopen($host.'.txt','w+');
$fw = fwrite($fp, $contents);
curl_close ($ch);
fclose($fp);

?>

</body>
</html>

 

Ok, I am having a problem here.

I have an automation script I am trying to make, but I hit a road block.

 

I need to open up multiple URL's from using an array of URL's stored in my config.ini file.

It looks like this:

 

Config.ini
Host[] = www.websitea.com
Host[] = www.websiteb.com
Host[] = www.websitec.com
Host[] = www.websited.com

 

I want to use curl_setopt to open up each one of the urls stored in $host.

 

If I use...

print_r ($host);

 

...I get this output:

 

Array ( [0] => www.websitea.com [1] => www.websiteb.com [2] => www.websitec.com [3] => www.websited.com ) 

 

Now, I need to take those websites in the array and open each one of them using curl_unit.

 

I tried doing this... 

 curl_setopt($ch, CURLOPT_URL, $host);

 

Then

$fp = fopen($host.'.txt','w+');

 

But I knew that wouldnt work.

 

Basically, I need to open up all of the pages listed in the .ini file and save the HTML Content of those pages to their own text file, that's named after the URL.

I figured I could open an array of URLS from my INI and write each one to their own text file.

 

 

Example:

websitea.com.txt (HTML Content from www.websitea.com)

websiteb.com.txt (HTML Content from www.websiteb.com)

websitec.com.txt (HTML Content from www.websitec.com)

websited.com.txt (HTML Content from www.websited.com)

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.