将网站数据恢复为excel

时间:2013-11-01 14:55:18

标签: excel vba

我正在尝试使用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>

1 个答案:

答案 0 :(得分:0)

蒂姆建议采用代码方式来做这件事,这在技术上是正确的。我在这里反复提出同样的建议: VBA spliting results from html imported table into excel 基本上,使用宏录制器,然后为数据创建HTML查询。 请参阅我的博客文章。 http://automatic-office.com/?p=344

很多方法可以给猫皮肤涂抹,但这很简单。