VBA正在抓取不在HTML源文件中的生成内容

VBA scraping generated content which is not in the HTML source file

本文关键字:源文件 抓取 HTML VBA      更新时间:2023-09-26

我制作了一个VBA代码来从网页上获取一些产品价格。

我可以让它为所有我想要的网站工作,除了一个。在这个特定的网站上,价格没有显示在页面的HTML代码中,但据我在网上搜索时所知,它们是由JavaScript本地生成的。

我怎样才能勉强买到这些价格?

我使用这种方法来获取页面来源,然后解析响应文本以获得我需要的信息,如产品名称和链接,但我无法获得价格:

Set xhr = New MSXML2.XMLHTTP60
        adresa = "http://www.elefant.ro/carti/natura"
        With xhr
            .Open "GET", adresa, False
            .send
            If .readyState = 4 And .Status = 200 Then
                Set doc = New MSHTML.HTMLDocument
                corp = .responseText
            Else
                Cells(i, 2) = "error"
            End If
        End With

这是我得到的页面的HTML代码的一部分,价格应该在哪里:

<div class="js_PriceContainer" style="display: none">
            <div>
                <div class="product_old_price js_oldPrice">
                    <a class="FFTracking" rel=""  href="/carti/natura/resurse-naturale/ghidul-culegatorului-de-ciuperci-211009.html"><span class="js_basePrice"></span> lei</a>
                </div>
                <div class="product_discount js_ProductDiscount">
                    <a class="FFTracking" rel=""  href="/carti/natura/resurse-naturale/ghidul-culegatorului-de-ciuperci-211009.html">(<span class="js_discount"></span>%)</a>
                </div>
            </div>
            <!-- <div class="promo_bf">
                                            <div class="product_old_price"></div>
                        <div class="product_discount"></div>
                                    </div> -->
            <div style="clear:both"></div>
            <div class="product_final_price js_FinalPriceContainer">
                <a class="FFTracking" rel=""  href="/carti/natura/resurse-naturale/ghidul-culegatorului-de-ciuperci-211009.html">
                    <span class="js_finalPrice js_promoNonBf"></span>
                    <span class="js_finalPrice js_promoBf"></span>
                </a>
            </div>
        </div>

请帮忙!谢谢

在项目中导入QT WebKit,并在抓取之前使用WebKit的强大功能来渲染网页。本指南解释了如何在LXMLscraper中实现webkit。