2012-12-08 26 views
0

所以我有這樣的HTML瀏覽:檢索HTML件

<div id="verify-purchase-modal" data-role="dialog"> 
    <div data-role="header"> 
     <h1>Buy Item</h1> 
    </div> 
    <div data-role="content"> 
<form action="/Catalog/ProcessPurchase" method="post">    <div></div> 
       <div class="catalog-modal-image"> 
         <img src="http://t6ak.roblox.com/cd4fad953f57e86e537da262b3503e04" alt="General Badblox" /> 

       </div> 
       <div> 
        Would you like to buy the <strong>"General Badblox"</strong> Package 
        from ROBLOX for 
         <span class="currency-robux">400</span>? 
       </div> 
       <div class="ui-grid-a no-margin-grid add-large-margin-top clear"> 
        <div class="ui-block-a"> 
         <input name="__RequestVerificationToken" type="hidden" value="9EZgfWvmFbfVWWSvuIhMrWWs6E2XmjONlejy5JJRYQh5KBbttyCtH/ve1KcPq1MbLYnj6ktT8SyGfFrWRYshUMLUI1mmthTs1KJNizlPG8T809is5Y0ZJYJyqaTCmnom2P6vVpmnZATlqsFtN4pVhd1QH94cZbLU2eszES4+QLeES2Cv" /> 
         <input data-val="true" data-val-number="The field CurrencyType must be a number." data-val-required="The CurrencyType field is required." id="CurrencyType" name="CurrencyType" type="hidden" value="1" /> 
         <input data-val="true" data-val-number="The field AssetID must be a number." data-val-required="The AssetID field is required." id="AssetID" name="AssetID" type="hidden" value="98755232" /> 
         <input data-val="true" data-val-number="The field UserAssetOptionID must be a number." data-val-required="The UserAssetOptionID field is required." id="UserAssetOptionID" name="UserAssetOptionID" type="hidden" value="0" /> 
         <input type="submit" value="Buy Now" data-theme="d" /> 
        </div> 
        <div class="ui-block-b"> 
         <a id="cancelPurchase" data-rel="back" data-role="button" data-theme="f">Cancel</a> 
        </div> 
       </div> 
        <div class="dialog-footnote"> 
         Your balance after this transaction will be <span class="currency-robux">11,910</span>. 
        </div> 
</form> 
    </div> 
</div> 

我用VB得到來自網站。在它說「400?」的行中我想提取400,所以我將所有HTML保存爲一個字符串。我試圖做簡單的,只是使用一個子字符串來獲取它,但我一直得到一個OOB(超出界限)錯誤。請記住,我正在嘗試在Visual Basic中做到這一點。

 Dim daHtml As String = WebBrowser1.Document.Body.OuterHtml 
    Msg(daHtml.Substring(daHtml.IndexOf("currency-robux"">"), daHtml.IndexOf("</span>?"))) 
+0

涉及http://htmlagilitypack.codeplex.com/的解決方案將是一個好的開始。 – MatthewMartin

回答

0

在VB中,子字符串的工作方式與其他語言不同。在我看來,這是錯誤的。它不是substring(startIndex,endIndex),而是substring(startIndex,length)。所以,你正在尋找的東西,開始於:

daHTML.IndexOf("currency-robux"">") 

和雲的長度:

daHTML.indexOf("</span>?") 

也因此,去字符串的範圍之外。