0

我正在尝试使用 VBA 在 Excel 中自动执行页面抓取程序,但由于我想要的字段没有 ID,因此难以从网页中获取结果,我已经复制了下面的源代码,我认为它包含在表格中?如何使用 td Class 和 class 获取数据?

<table>
                <tbody>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Date of Liability</span></td>
                        <td class="vehicledetailstableright"><span class="bodytext">01 07 2014</span></td>
                    </tr>
                            <tr>
                                <td class="vehicledetailstableleft"><span class="bodytextbold">Date of First Registration</span></td>
                                <td class="vehicledetailstableright"><span class="bodytext">02 07 2013</span></td>
                            </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Year of Manufacture</span></td>
                        <td class="vehicledetailstableright"><span class="bodytext">2013</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Cylinder Capacity (cc)</span></td>
                        <td class="vehicledetailstableright"><span class="bodytext">2993cc</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">CO&#8322; Emissions</span></td>
                        <td class="vehicledetailstableright"><span class="bodytext">129 g/km</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Fuel Type</span></td>
                        <td class="vehicledetailstableright"><span id="fueltype" class="bodytext">HEAVY OIL</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Export Marker</span></td>
                        <td class="vehicledetailstableright"><span id="exportmarker" class="bodytext">N</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Status</span></td>
                        <td class="vehicledetailstableright"><span id="vehiclelicencestatus" class="bodytext">Licence Not Due</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Colour</span></td>
                        <td class="vehicledetailstableright"><span id="colour" class="bodytext">BLUE</span></td>
                    </tr>
                    <tr>
                        <td class="vehicledetailstableleft"><span class="bodytextbold">Vehicle Type Approval</span></td>
                        <td class="vehicledetailstableright"><span class="bodytext">M1</span></td>
                    </tr>
                        <tr>
                            <td class="vehicledetailstableleft"><span class="bodytextbold">Date of Last V5C Issued</span>
                            </td>
                            <td class="vehicledetailstableright"><span class="bodytext">No Result Found</span> 
                            </td>
                        </tr>
4

1 回答 1

0

Tim 建议采用一种代码繁重的方式来实现它,而且它在技术上是正确的。我在这里反复建议同样的事情: VBA split results from html import table into excel 基本上,使用宏记录器,然后为数据创建一个 HTML 查询。也请参阅我的博客文章。 http://automatic-office.com/?p=344

给猫剥皮的方法很多,但这是最简单的方法。

于 2013-11-01T17:37:26.130 回答