0

I am very new to PHP, its not my domain however right now I have a need to pull a certain value from a website, I looked up on the internet and found the following function which I implemented as per my need:

          <?php
          $curl_handle=curl_init();
          curl_setopt($curl_handle,CURLOPT_URL,'http://www.indiagoldrate.com/gold-rate-in-mumbai-today.htm');
          curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
          curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
          $buffer = curl_exec($curl_handle);
          curl_close($curl_handle);
          if (empty($buffer))
          {
              print "Sorry, example.com are a bunch of poopy-heads.<p>";
          }
          else
          {
              print $buffer;
          }
          ?>

As of now I am able to retrieve the whole page, but I am only interested in one value from the said page, I need ideas of how to do it?

Code of the webpage I need: (Simple View source)

      <tr>
<td>MUMBAI<BR>Thu, Jul 25th, 2013</td>
<td><TABLE class="innerTable">
<TR>
    <TD>1g </TD>
    <TD>Rs. 2,595</TD>
</TR>
<TR>
    <TD>8g</TD>
    <TD>Rs. 20,760</TD>
</TR>
<TR>
    <TD>10g</TD>
    <TD>Rs. 25,950</TD>
</TR>
<TR>
    <TD>100g</TD>
    <TD>Rs. 2,59,500</TD>
</TR>
<TR>
    <TD>1 KG</TD>
    <TD>Rs. 25,95,000</TD>
</TR>
</TABLE></td>
<td><TABLE class="innerTable">
<TR>
    <TD>1g </TD>
    <TD>Rs. 2,795</TD>
</TR>
<TR>
    <TD>8g</TD>
    <TD>Rs. 22,360</TD>
</TR>
<TR>
    <TD>10g</TD>
    <TD>Rs. 27,950</TD>
</TR>
<TR>
    <TD>100g</TD>
    <TD>Rs. 2,79,500</TD>
</TR>
<TR>
    <TD>1 KG</TD>
    <TD>Rs. 27,95,000</TD>
</TR>
</TABLE></td>

I am interested in this part:

1g Rs. 2,595

user2613996
  • 117
  • 1
  • 2
  • 8
  • Parse through the DOM http://php.net/manual/en/domdocument.loadhtmlfile.php – SubjectCurio Jul 25 '13 at 08:47
  • DOMDocument, XPath, simple_html_dom, phpquery – DevZer0 Jul 25 '13 at 08:48
  • I have a need to update one element of another XML file with the value I retrieve, which method will best suit my need? – user2613996 Jul 25 '13 at 08:49
  • This question lack any research. A simple search on either Google or this site yield a lot of possibilities. – PeeHaa Jul 25 '13 at 08:50
  • What part of the html do you need (do you have a ID or class name for the element you're looking for?) – Remko Jul 25 '13 at 08:51
  • @PeeHaa I wrote the same in the problem description, of what I found and used and what problem I faced. – user2613996 Jul 25 '13 at 08:52
  • Because the HTML of the page is invalid domDocument & DOMXPath won't work (wouldn't be suprised if the dom is mallformed to prevent content scraping). Maybe if you'll find another source of this data with valid html I will be able to write a parser for you. – Remko Jul 25 '13 at 09:14
  • Thank You Let me search for another page, I was trying to use plaintext; ?> But Invain, throws a server error – user2613996 Jul 25 '13 at 09:30
  • Can we get it from this URL: http://www.sify.com/finance/gold_rates/? I am interested in gold rates at Mumbai. – user2613996 Jul 25 '13 at 09:32
  • http://www.gitanjalijewels.com/category.php?id=39 – user2613996 Jul 25 '13 at 09:41
  • Because the question has been marked as duplicate I can't give you the answer. I have created a script that will parse it for you (including documentation). Could you recreate the question so it won't be seen as duplicate and I will provide you with a answer. – Remko Jul 25 '13 at 11:53
  • @RMK please refer to: http://stackoverflow.com/questions/17872965/how-to-pull-a-value-from-a-website-using-curl-in-php Thanks a ton mate!! – user2613996 Jul 26 '13 at 04:34

1 Answers1

0

get simple_dom_html.php file and include it.

$html = str_get_html($buffer);
$html->find('any class etc');
M Shahzad Khan
  • 935
  • 1
  • 9
  • 22