2016-01-22 155 views
-1

我能够得到一个网站的编码与file_get_contents但我希望能够得到某些值的HTML。这段代码总是相同,但是html标签之间的值会随时变化。这是HTML代码:PHP网页抓取

<div class="cheapest-bins"> 
     <h3>Cheapest Live Buy Now</h3> 
     <table> 
      <tbody><tr> 
       <th>Console</th> 
       <th>Buy Now Price</th> 
      </tr> 
      <tr class=" active"> 
       <td class="xb1">XB1</td> 
       <td>1,480,000</td> 
      </tr> 
      <tr class=""> 
       <td class="ps4">PS4</td> 
       <td>1,590,000</td> 
      </tr> 
      <tr class=""> 
       <td class="x360">360</td> 
       <td>---</td> 
      </tr> 
      <tr class=""> 
       <td class="ps3">PS3</td> 
       <td>2,800,000</td> 
      </tr> 
     </tbody></table> 
    </div> 

我该怎么去得到:1,480,000 .. 1,590,000 .. ---和2,800,000?

回答

2

简短的回答: 找到一个CSS选择库如https://github.com/tj/php-selector 那么你可以抓住所有td:last-child元/ innerHTML的

你你可以只刚刚 preg_match_all('#<td>(.*?)</td>#', $html, $matches);

+0

由于具体的例子,这个完美的作品! –