Modernvox Posted October 30, 2009 Share Posted October 30, 2009 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/ Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 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.. Yeah. I want to open the first link check for email address then close and open second etc, etc.. Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947500 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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.. 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? Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947502 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 If no one feels like helping me complete this code how about listing a few functions i should look into to achieve the end result? Would be much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947504 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947510 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947512 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 The found URL's are $link ie foreach ($matches[1] as $link){ echo file_get_contents($link); } Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947517 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947520 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947523 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947527 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 The code i posted should "Open" it Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947529 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947530 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 Anyone know why i am getting this error? Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947557 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 .... Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947573 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 you have a trailing slash..so try echo file_get_contents("http://southcoast.craigslist.org/sss".$link); Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947579 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 you have a trailing slash..so try echo file_get_contents("http://southcoast.craigslist.org/sss".$link); Will try this as soon as i re-install Apache as it just died on me. Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947589 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947605 Share on other sites More sharing options...
DavidAM Posted October 30, 2009 Share Posted October 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947610 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947833 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 Try using cURL instead, see what errors you get Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947839 Share on other sites More sharing options...
salathe Posted October 30, 2009 Share Posted October 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947856 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 After stripping the /sss there were no differences. Same error. Doesn't look like there's enough code in my script to achieve this next step anyhow. Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947876 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947924 Share on other sites More sharing options...
MadTechie Posted October 30, 2009 Share Posted October 30, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947933 Share on other sites More sharing options...
Modernvox Posted October 30, 2009 Author Share Posted October 30, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179560-solved-requires-your-assistance-desperately/#findComment-947935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.