Scrape desired data from html code using PHP

Tuesday, November 3, 2015

Below is the html code from which I want to fetch some data.







107

<span class="bold h5">backers</span>
</div>



€7,279

<span class="bold h5">
pledged of <span class="money eur no-code">€8,000</span> <span class="mobile-hide">goal</span>
</span>
</div>
<span data-duration="30.041666666666668" data-end_time="2015-11-27T14:32:42-05:00" data-hours-remaining="566.7967307435142" id="project_duration_data"></span>

23

<span class="text bold h5">days to go</span>
</div>
</div></div>
</div>
</div>
</div>


From above html code I have to fetch following data:





  • 107 backers

  • €7,279 pledged of €8,000 goal

  • 23 days to go




I successfully scraped the first one but not able to fetch 2nd and 3rd one.
Below is my PHP code (using CURL) to fetch the first one.



$html = get($url); //get function uses CURL and gets html data
$pattern = "/<p class=\"h3 mb3\">(.*?)<\/p>/s";
preg_match($pattern,$htm,$match);
return $match[1];

0 comments:

Post a Comment