2015-04-02 68 views
1

我做了一個VBA代碼來從網頁上刮取一些產品價格。VBA抓取不在HTML源文件中的生成內容

我可以使它適用於我想要的所有網站,除了一個。在這個特定的網站上,價格沒有顯示在頁面的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> 

請幫幫忙! 謝謝!

+0

如果您需要讀取客戶端上生成的動態內容,那麼您應該(例如)自動化IE來加載頁面並使用自動化來讀取內容。如果您使用IE Developer工具,那麼您應該能夠查看呈現的內容(而不僅僅是從服務器提供的HTML) – 2015-04-02 23:53:01

回答

0

在您的項目中導入QT WebKit並使用webkit的強大功能在抓取前呈現網頁。 This guide解釋瞭如何在LXML scrapper中實現webkit。

+0

謝謝,但是在閱讀完這些問題之後,我可以告訴你,這超出了我的業餘程序員技能。 ..有一個更簡單的verion? – user3254924 2015-04-03 13:08:45

+0

如果這不是一個編程項目,沒有準備好的scrappers有用嗎? – 2015-04-03 13:43:14

+0

我願意編程,所以我也可以學到一些東西。 – user3254924 2015-04-03 15:16:54