Checking the Prime Rate
Results 1 to 9 of 9

Thread: Checking the Prime Rate

  1. #1
    Junior Member Wefferiscoding's Avatar
    Join Date
    May 2013
    Posts
    10

    Smile Checking the Prime Rate

    I am studying Web design and am in the beginning. I am getting it all pretty good, but this has got me stumped because I don't know how to change the example code I have to make it work with the results I need. Any help out there?

    This is what I have to do: Using the screen scraping technique, write the script to look up and retrieve the current LIBOR prime rate from Bankrate.com.

    This is the example code I have:
    PHP Code:
        <body>
            <?php
                
    //choose rate to look at
                
    $symbol 'AMZN';
                    echo 
    '<h1>Prime Rate for ' .$symbol '</h1>';
                    
                    
    $url 'http://finance.yahoo.com/d/quotes.csv' .
                        
    '?s=' $symbol '&e=.csv&f=sl1d1t1c1ohgv';
                        
                if (!(
    $contents file_get_contents($url))) {
                    die(
    'Failure to open ' $url);
                }
                
                
    //extract relavant data
                
    list($symbol$quote$date$time) = explode(','$contents);
                
    $date trim($date'"');
                
    $time trim($time'"');
                
                echo 
    '<p>' $symbol ' was last reported at: ' $quote '</p>';
                echo 
    '<p>Quote current as of ' $date 'at' $time '</p>';
                
                
    //acknowledge source
                
    echo'<p>This information retrieved from<br /><a href="' $url '">' $url '</a>.</p>';
                
    ?>
        </body>
    The problem that I am having is in this row:
    $url = 'http://finance.yahoo.com/d/quotes.csv' .
    '?s=' . $symbol . '&e=.csv&f=sl1d1t1c1ohgv';

    I do not know what '?s=' . $symbol . '&e=.csv&f=sl1d1t1c1ohgv'; means and what it has to do with the website that this code is getting the stock quote from.
    I am hoping this is making sense and would love it if anybody out there can at least explain to me how I would find the equivalent code for the bankrate.com and LIBOR prime rate so that the code shows on my website the LIBOR prime rate.
    Thanks so much!
    Last edited by bradgrafelman; 05-21-2013 at 06:47 PM. Reason: bbcode tags added

  2. #2
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,697
    Welcome to PHPBuilder! Please use [php][/php] BBCode tags around all PHP code to make it easy on board layout and other users analyzing your code.

    Quote Originally Posted by Wefferiscoding
    I do not know what '?s=' . $symbol . '&e=.csv&f=sl1d1t1c1ohgv'; means and what it has to do with the website that this code is getting the stock quote from.
    In order to write the example code you have, some ardent programmer went to Yahoo's Finance site and observed what happened there when he/she wanted to read the stock quote for Amazon.com.

    One of the first things *you* should do is visit bankrate.com and find where the LIBOR is displayed. Take a look at the source code around that area, as that's what you'll be receiving back from a call to file_get_contents().

    And, finally, this is probably over the top for a newbie, but have a look at stream_context_create and be a good Netizen:

    PHP Code:
    $context_options = array(
      
    'http'=>array(
        
    'timeout'=>600,
        
    'method'=>"GET",
        
    'header'=>"Accept-language: en\r\n" .
                  
    "User-Agent: Wefferiscoding@yourdomain.com/0.1 (Windows i386; U; en-us) Wefferiscoding_Libor_scraper 0.1\r\n"
      
    )
    );

    $context stream_context_create($context_options); 
    Then when you call file_get_contents():
    PHP Code:
    $data file_get_contents("http://bankrate.com/something",0,$context); 
    HTH,
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  3. #3
    Junior Member Wefferiscoding's Avatar
    Join Date
    May 2013
    Posts
    10

    Cool

    Thanks for your help and you are right, the end code is way over my head yet, although I could pick out some of it that made sense.
    I looked at the page source and it is all in Javascript, so I am not sure what to look for. The problem that I am having is with this part of the code:

    PHP Code:
    ?s=' . $symbol . '&e=.csv&f=sl1d1t1c1ohgv'; 
    This is what is throwing me off. I am not sure how to find this information for the website I want to use. Does that make sense?
    Thanks!
    Beth

  4. #4
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,697
    Quote Originally Posted by Wefferiscoding View Post
    I looked at the page source and it is all in Javascript, so I am not sure what to look for.
    It may not be possible; I'll take a brief look.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  5. #5
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,697
    Hmm; with either a browser (Chrome in this case) or PHP's file_get_contents() from a UNIX CLI, at www.bankrate.com/rates/interest-rates/libor.aspx, I find LIBOR information in a table in HTML:
    Code:
                        <tr bgcolor="#FFFFFF">
                            <td align="left" class="tabledataoddnew"><a href="1-month-libor.aspx"><strong>1 Month LIBOR Rate</strong></a></td>
                            <td align="center" class="tabledataoddnew">0.20</td>
                            <td align="center" class="tabledataoddnew">0.20</td>
                            <td align="center" class="tabledataoddnew">0.24</td>
                        </tr>
                    
                        <tr bgcolor="#FFFFFF">
                            <td align="left" class="tabledatanew"><a href="3-month-libor.aspx"><strong>3 Month LIBOR Rate</strong></a></td>
                            <td align="center" class="tabledatanew">0.27</td>
                            <td align="center" class="tabledatanew">0.28</td>
                            <td align="center" class="tabledatanew">0.47</td>
                        </tr>                
                    
                        <tr bgcolor="#FFFFFF">
                            <td align="left" class="tabledataoddnew"><a href="6-month-libor.aspx"><strong>6 Month LIBOR Rate</strong></a></td>
                            <td align="center" class="tabledataoddnew">0.42</td>
                            <td align="center" class="tabledataoddnew">0.43</td>
                            <td align="center" class="tabledataoddnew">0.74</td>
                        </tr>
    Looks perfect for scraping to me. Dust off your file_get_contents() and read a little about DOMDocument and you should be good to go ... no query_string involved
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  6. #6
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,414
    Did a professor/teacher set this assignment? If so, I personally would refuse to complete it for two reasons:

    1. Screen scraping is pretty much one of the worst ways to retrieve external data. It's prone to breaking easily and quite often violates an AUP/ToS/etc.
    2. Speaking of that last bit, Bankrate.com does indeed have a ToS, and it just so happens to say the following:

      Quote Originally Posted by Bankrate.com ToS
      You agree that you will not use any robot, spider, scraper, deep link or other similar automated data gathering or extraction tools, program, algorithm or methodology to access, acquire, copy or monitor the Site or any portion of the Site or for any other purpose, without Bankrate's express written permission which may be withheld in Bankrate's sole discretion.
      (The text in bold is what I personally would read aloud, verbatim, to my professor/teacher as I refuse to complete the assignment and request an alternative one. )

  7. #7
    Junior Member Wefferiscoding's Avatar
    Join Date
    May 2013
    Posts
    10
    dalecosp:
    Thanks so much for all your help!!

    bradgrafelman:
    Thanks so much for that...yikes!

  8. #8
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,863
    I remember when IT curricula had sections on applied professional ethics. Am I showing my age or something?
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  9. #9
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,697
    Quote Originally Posted by Weedpacket View Post
    I remember when IT curricula had sections on applied professional ethics. Am I showing my age or something?
    Quite possibly, you sweet old pedantic curmudgeon you

    Actually, I am too; the topic sounds like a fairly good one for the EL ... problem being that some of us ( ) have probably promoted ourselves or our work to the point that I'm not sure things could be discussed as openly as one might hope ....

    As regards my scraping projects, I'm told that sales has verified willingness to participate before they turn me loose on a company's site ...
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •