2016-08-16 124 views
0

我正在使用vba(& internetexplorer對象)從以下網站http://www.isincodes.net/convert-cusip-to-isin.php將CSUIP轉換爲ISIN(這些是金融安全唯一標識碼)。VBA簡單解析

我迄今所創建的VBA代碼(按照以下順序)認爲: 1.操縱美國/加拿大下拉框中 2.輸入我的CUSIP到輸入框 3.點擊「隱蔽」按鈕

Sub cusip_is2() 

'declare variables 
Set objie = CreateObject("internetExplorer.Application") 

objie.Visible = True 

'go to website 
objie.navigate ("http://www.isincodes.net/convert-cusip-to-isin.php") 
Do 
DoEvents 
Loop Until objie.readyState = 4 

'input the CA in the country ID step1 
objie.document.getelementbyID("country").Value = "CA" 

'input 912796HQ5 in text box as desired CUSIP to convert 
objie.document.getelementbyID("appendedInputButton").Value = "912796HQ5" 


'press the button to convert 
Set ElementCol = objie.document.getElementsByTagName("button") 
For Each btnInput In ElementCol 
    btnInput.Click 
Next btnInput 

'wait until the pages loads (not sure if I need this) 
Do 
DoEvents 
Loop Until objie.readyState = 4 

'added extra few seconds incase HMTL document is updating 
Application.Wait Now + TimeSerial(0, 0, 1) 

'created userform to look at the data to see if I can find the converted CUSIP - WHICH I CANNOT (HELPPPPP!!!!) 
Userfrom_Web_Code.Textbox_Webform.Text = objie.body.innerText 
Userfrom_Web_Code.Show 


'clean up and try again for the next failure LOL 
objie.Quit 
Set objie = Nothing 
End Sub 

從我的研究中,我知道我一直在獲取源代碼,但是我想要DOM,這是我遇到問題的地方。一旦我爲國家和CUSIP「912796HQ5」輸入了「CA」,請參閱網站上的源代碼摘錄,並注意帶結果的id標記不包含任何內容。

<p>Enter a CUSIP and a correct ISIN will be calculated for you, if possible:</p> 
        <form class="form-inline"> 
         <div class="input-append"> 
          <select id="country" style="width:60px;"> 
           <option value="CA">CA</option> 
           <option value="US" selected>US</option> 
          </select> 
          <input type="text" maxlength="9" class="span3" id="appendedInputButton"> 
          <button type="button" class="btn">Convert</button> 
         </div> 
        </form> 

        <div id="results"></div> 

        <br><br> 
            </div> 

       <div class="span4"> 
        <h4>What is a CUSIP?</h4> 
        <p>A CUSIP is a 9-character alphanumeric code which identifies a North American financial security.</p> 
        <p> 
         A CUSIP consists of three parts:<br> 
         &#8226; A six-character issuer code<br> 
         &#8226; A two-character issue number<br> 
         &#8226; A single check digit.<br><br> 
         For example: 780259206 (Royal Dutch Shell-A) 
        </p> 

相反,當我檢查檢查元件,它帶我到「DOM」那麼我可以在ID結果看到這一點。

<div id="results" style="display: block;"><br> 
 
<b>Strict Standards</b>: Non-static method Validate_CUSIP::validate() should not be called statically in <b>/home/isincode/public_html/action/c.php</b> on line <b>15</b><br> 
 
<p class="text-success"><strong>Correct ISIN: CA912796HQ58</strong></p></div>

任何人都可以請幫我在VBA解決這個問題。

請注意,我知道你可以在vba/excel中自己創建一個算法來完成CUSIP到ISIN的轉換,但是我想在VBA中做這個項目來學習解析。我對編碼也很陌生,接觸有限,請善待並解釋你所建議的一切。

回答

1

請看看下面的編輯會適合你:

.... 
.... 
'added extra few seconds incase HMTL document is updated 
Application.Wait Now + TimeSerial(0, 0, 2) 

Dim ISIN As String 
ISIN = Right(objie.document.getelementbyID("results").innerText,12) 'the 12 rightmost characters 
Debug.Print "ISIN you are looking for is: " & ISIN 
.... 

編輯的代碼做一些有用與ISIN串

+0

嘿Carmelid,似乎是工作我家裏的電腦上,將嘗試並且在我的工作中,我遇到了一個問題。不能相信這只是LOL的一秒鐘。非常感謝您的時間也是爲了。 – deltahedge