PHP 网页抓取


PHP Web Page Scraping

我能够获得带有file_get_contents的网站编码,但我希望能够从html中获取某些值。这段代码始终相同,但 html 标记之间的值会不时更改。这是 HTML 代码:

<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?

简短的回答:查找 CSS 选择器库,例如 https://github.com/tj/php-selector然后你可以获取所有td:last-child元素/innerhtml

对于您的特定示例,您可以只 preg_match_all('#<td>(.*?)</td>#', $html, $matches);