【发布时间】:2018-11-02 23:41:00
【问题描述】:
我是抓取 HTML 的新手,几天来一直在尝试使用类名和 id 从隐藏字段中抓取值,但我仍然无法获取值。
我正在尝试从以下 HTML 中获取值 (4);
<input id="collectionQuantity" type="hidden" value="4">
这是从下面较大的摘录中摘录的;
<div class="lg-24 md-12 cols">
<input id="selectedBranchCode" type="hidden" value="OT4">
<input id="selectedBranchName" type="hidden" value="Ashton-under-Lyne">
<input id="collectionQuantity" type="hidden" value="4">
<button id="add_for_collection_button_3730P" title="Click here to add this item to your basket for collection" class="btn btn--lg btn--col fill " data-content="add-to-basket">Click & Collect</button>
<p id="branch_collection_3730P">4 in stock in <strong>Ashton-under-Lyne</strong> <a href="https://www.screwfix.com/jsp/cpc/cpcCheckStock.jsp?product_id=3730P" id="click_and_collect_3730P" class="_btn--link">Change store</a></p>
</div>
我已经尝试了很多获得价值的方法。 我认为我最亲近的是;
sh01.Cells(r, 5) = HTML.getElementsByClassName("lg-24 md-12 cols")(3).innertext 'product stock
sh01.Cells(r, 5) = HTML.getElementsByTagName("p")(7).innertext 'product stock
sh01.Cells(r, 5) = HTML.getElementById("branch_collection_" & z_sh01.Cells(y, 2)).innertext 'product stock
sh01.Cells(r, 5) = HTML.getElementsByClassName("lg-24 md-12 cols")(3).getElementById("collectionQuantity").Value 'product stock
sh01.Cells(r, 5) = HTML.querySelector("# branch_collection_" & z_sh01.Cells(y, 2)).innertext 'product stock
sh01.Cells(r, 5) = HTML.getElementById("collectionQuantity").innertext 'product stock
提前感谢您的帮助。
伊恩
【问题讨论】:
标签: html excel vba web-scraping scrape