Jump to content

Recommended Posts

You guys worked me up and then left me hanging with this project. No, not really, but I am near the end and hoping to get this code running.

 

I have already opened the URL, grabbed the list of links and now i want to open one of these links.

I have tried a few different methods with no luck.

 

The thing that is confusing me is the fact that I won't know the URL of each link i want to open in advance so therefor I don't know what to tell the script i.e, what to open?

 

Links i want to open:

http://i266.photobucket.com/albums/ii246/Pencilman_2008/links.jpg

 

 

Current Code:

<?php  
    function curlURL($url) {  
        $curl = curl_init();  
        curl_setopt($curl, CURLOPT_URL, $url);  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');  
        $output = curl_exec($curl);  
            return $output;  
    }  
     
   $curlResults = curlURL("http://southcoast.craigslist.org/sss/");  
   $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#';
   preg_match_all( $pattern, $curlResults, $matches);

echo "<pre>\n";
echo "Links:\n\n";
foreach ($matches[1] as $link):
   echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n";
endforeach;
echo '</pre>';



?> 

 

1. if its desperate, you should post in the freelance section

2. this is basically a double post [link]

3. leaching is one thing but leaching email addresses..  :o

Yeah. I want to open the first link check for email address then close and open second etc, etc..

 

1. if its desperate, you should post in the freelance section

2. this is basically a double post [link]

3. leaching is one thing but leaching email addresses..  :o

Yeah. I want to open the first link check for email address then close and open second etc, etc..

 

Yeah, I want to find specific items for sale an auto respond to the sellers before someone else does?

Is that bad?

1. Double posting is against the rules

2. you don't need to open every link find an item

3. you have all the functions you need (are technically need to repeat what you have)

 

1. Understood, I marked previous post as solved, My apologies.

2. Ok

3. I can't repeat what i have because i knew what the first URL was that found these links, now i need to open the individual links which is confusing me a bit, but I will search per your suggestions and see if i can't figure this out again.

 

Thanks Sir!

The found URL's are $link

ie

foreach ($matches[1] as $link){
echo file_get_contents($link);
}

 

Yeah understood and i get the following error:

Warning: file_get_contents(/cto/1443625200.html) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\xampp\htdocs\test4.php on line 23

 

Is this becasue it is reading it as text instead of a link or am i suppose to be storing these somewhere?

Oh your need the full path

 

echo file_get_contents("http://southcoast.craigslist.org/sss/$link");

 

Note: this is just an example it will just echo the contents of the pages to screen,

 

Yeah, I already have the contents listed on the screen i.e, the links i would like to open. I want to just open one of those, that's all?

The code i posted should "Open" it

 

Code you posted returns the following:

Warning: file_get_contents(http://southcoast.craigslist.org/sss//cto/1443475496.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\xampp\htdocs\test4.php on line 22

Yeah ,,,Still NOT working. Getting the following error:

Warning: file_get_contents(http://southcoast.craigslist.org/sss/pts/1443545972.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\test4.php on line 23

 

 <?php  
    function curlURL($url) {  
        $curl = curl_init();  
        curl_setopt($curl, CURLOPT_URL, $url);  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');  
        $output = curl_exec($curl);  
            return $output;  
    }  
     
   $curlResults = curlURL("http://southcoast.craigslist.org/sss/");  
   $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#';
   preg_match_all( $pattern, $curlResults, $matches);

echo "<pre>\n";
echo "Links:\n\n";
foreach ($matches[1] as $link):
   echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n";
endforeach;
echo '</pre>';


echo file_get_contents("http://southcoast.craigslist.org/sss".$link);
?> 

Warning: file_get_contents(http://southcoast.craigslist.org/sss/pts/1443545972.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\test4.php on line 23

 

Did you read the error message?

Warning: file_get_contents(http://southcoast.craigslist.org/sss/pts/1443545972.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\test4.php on line 23

 

Did you read the error message?

 

Absolutely!  The link worls when accessed outside of the script. Only fails being ran from the script.

Absolutely!  The link worls when accessed outside of the script. Only fails being ran from the script.

 

The link in the quote does not work, it's a 404 page not found error: http://southcoast.craigslist.org/sss/pts/1443545972.html  The "/sss" part should not be there.

 

 

Ok the link is now opening. Can i (should i) now use preg_match_all to find the address, copy it and close the link/page?

 

And...Will i be able to open the next link in the list?

 

<?php  
    function curlURL($url) {  
        $curl = curl_init();  
        curl_setopt($curl, CURLOPT_URL, $url);  
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');  
        $output = curl_exec($curl);  
            return $output;  
    }  
     
   $curlResults = curlURL("http://southcoast.craigslist.org/sss/");  
   $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#';
   preg_match_all( $pattern, $curlResults, $matches);

echo "<pre>\n";
echo "Links:\n\n";
foreach ($matches[1] as $link):
   echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n";
endforeach;
echo '</pre>';


echo file_get_contents("http://southcoast.craigslist.org".$link);


?> 

Ok the link is now opening. Can i (should i) now use preg_match_all to find the address, copy it and close the link/page?

Yep a RegEx seams the best option

 

And...Will i be able to open the next link in the list?

of course you have an array you can loop thought!

Ok the link is now opening. Can i (should i) now use preg_match_all to find the address, copy it and close the link/page?

Yep a RegEx seams the best option

 

And...Will i be able to open the next link in the list?

of course you have an array you can loop thought!

 

Will Do, thanks MT ;D

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.