Bitcoin Forum

Economy => Services => Topic started by: sal002 on May 03, 2013, 12:33:34 PM



Title: Simple PHP Scraper
Post by: sal002 on May 03, 2013, 12:33:34 PM
I need a quick and dirty PHP script written that scrapes the highest price for converting Bytecoin into BTC as posted here - http://exchange.bytecoin.in/.

Any takers?


Title: Re: Simple PHP Scraper
Post by: bitcoinator on May 03, 2013, 01:21:33 PM
Should it consider amount of bte to be converted?


Title: Re: Simple PHP Scraper
Post by: sal002 on May 03, 2013, 01:40:11 PM
Nope - just get the price.  SImple scraper.


Title: Re: Simple PHP Scraper
Post by: bitcoinator on May 03, 2013, 01:42:19 PM
Sounds simple, I will do it.


Title: Re: Simple PHP Scraper
Post by: Chemicalbro on May 03, 2013, 02:07:22 PM
<?php

$url = "http://exchange.bytecoin.in/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

preg_match_all("|<[^>]+>(.*)</[^>]+>|U", $curl_scraped_page, $out);

echo "Max buy: " . $out[1][10] . "\n";

?>


Title: Re: Simple PHP Scraper
Post by: sal002 on May 03, 2013, 02:14:45 PM
Genius - can I send you a small tip?


Title: Re: Simple PHP Scraper
Post by: Chemicalbro on May 03, 2013, 02:20:16 PM
Sure, if you like. Just note that if the page changes format (ie. more tags, etc get inserted before the buy price), that quick grab will break. You'd have to change the array number to match the change.

1HcNqP6uzqEcmsNe4uDu38qDWXonU2z6ci


Title: Re: Simple PHP Scraper
Post by: bitcoinator on May 03, 2013, 02:27:31 PM
Oh, wow... Really genious... Here is my solution since I did it too:

Code:
<?php                                                                                                                                          
  
function get_max_price_from_table($table){                                                                                                   
    
$max_price 0;                                                                                                                            
    
$rows $table->getElementsByTagName('tr');                                                                                                
    for (
$i 1$i $rows->length$i++)                                                                                                     
      
$max_price max($rows->item($i)->getElementsByTagName('td')->item(0)->nodeValue$max_price);                                           
    return 
$max_price;                                                                                                                         
  }                                                                                                                                            
                                                                                                                                               
  
$html file_get_contents("http://exchange.bytecoin.in/");                                                                                   
  
$DOM = new DOMDocument;                                                                                                                      
  
$DOM->loadHTML($html);                                                                                                                       
  
$tables $DOM->getElementsByTagName('table');                                                                                               
  echo 
get_max_price_from_table($tables->item(1));                                                                                             
?>

Just in case if you decide to tip: 1Hn7xud8i8pn7WSTNmHzjYe7gLz1XmpTQH :)


Title: Re: Simple PHP Scraper
Post by: sal002 on May 03, 2013, 02:29:05 PM
Good as well :)!


Title: Re: Simple PHP Scraper
Post by: Chemicalbro on May 03, 2013, 02:31:56 PM
I'd actually go with his, mine is REALLY quick and dirty, his is a little less so :p


Title: Re: Simple PHP Scraper
Post by: sal002 on May 04, 2013, 12:00:23 AM
Thank you both - tips sent.


Title: Re: Simple PHP Scraper
Post by: bitcoinator on May 04, 2013, 05:12:55 AM
Oh, wow, I am bitcoiner now, thanks! :)


Title: Re: Simple PHP Scraper
Post by: dooglus on May 25, 2013, 04:00:02 AM
Here's my version.  It's quicker because it avoids using the network at all:

Code:
<?php

print "We are in maintenance. Please come back later\n";


Title: Re: Simple PHP Scraper
Post by: sal002 on May 25, 2013, 04:26:47 AM
Here's my version.  It's quicker because it avoids using the network at all:

Code:
<?php

print "We are in maintenance. Please come back later\n";

+1 - well, it worked for a bit!


Title: Re: Simple PHP Scraper
Post by: dooglus on May 25, 2013, 04:40:23 AM
+1 - well, it worked for a bit!

Still works for me.  :)

In the same series, here's a script that will tell you what time it is:

Code:
<?php

print "21:40:51\n";

Inspired by the goon show (http://www.youtube.com/watch?v=-tjHlFPTwVk).