2017-10-22 8 views
0

未知数の行と列が不明なテーブルの最後の2列のすべてのセルからデータを取得しようとしています。私はVBScriptでこれを行う必要がありますが、これは難しかったです。テーブルの最後の2列からデータを取得

下の例では、5つの列ごとに2つの行があります。しかし、私の状況では、行と列の数はさまざまです。

行と列が変化しているので、私は年2015年最初の行の2016等2行目のとされ、最後の2列のデータを取得したいです私はデータを取得するための適切なスクリプトを見つけることができません。

データは、入力フィールドに解析する必要があるため、変数としてリストする必要があります。

<table id="calculations_data" class="key_figures togglable"> 
    <tr> 
     <th></th> 
     <th scope="col">Year 2012</th> 
     <th scope="col">Year 2013</th> 
     <th scope="col">Year 2014</th> 
     <th scope="col">Year 2015</th> 
     <th scope="col">Year 2016</th> 
     <th></th> 
    </tr> 
<tr id="turnover_data" class="data_row addaptive"> 
    <th class="title"><a href="#turnover_definition">Turnover</a></th> 
    <td>111</td> 
    <td>222</td> 
    <td>333</td> 
    <td>444</td> 
    <td>555</td> 
    </tr> 
</table> 

さらにデータは、私は、このスクリプトによってアクセスするWebサイトにあります。

Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
IE.Navigate "https://data.biq.dk/users/sign_in" 

注:上記のウェブサイトは、私は私のスクリプト経由で管理ログインが必要です。ログインの詳細を提供することはできません。

データがタグ内にある以下のコードを使用して成功しました。

Data_CompanyName = IE.document.getElementsByTagName("h1")(0).innerText 
Document.getElementByID("company_name").value = Data_CompanyName 
+0

ヌーンこの問題への提案された解決策で? 私は本当に助けを望んでいるので、私は立ち往生してきました。ありがとう! :-) – Sparcx

+0

投稿されたコードがあなたのために働くかどうか教えてください。 – Gurman

答えて

0

まず、そのテーブルのinnerHTMLを抽出し、XMLを解析する際にそのinnerHTMLを解析できます。これが最善のアプローチであるかどうかはわかりませんが、それは私のために働いています。

は、このコードを試してみてください。

set objIE = CreateObject("internetexplorer.application") 
objIE.visible = true 
objIE.navigate "https://data.biq.dk/users/sign_in"  '<--make sure the correct path is entered here(the one which takes you to that page containing the table) 
while objIE.readyState <>4 
    Wscript.sleep 1000 
Wend 
set objTable = objIE.document.getElementById("calculations_data") 
strxml = objTable.innerhtml 
set objXML = CreateObject("Microsoft.XMLDOM") 
objXML.async=False 
objXML.loadxml strxml 
set objRowNodes = objXML.selectnodes("//tr") 
for i=1 to objRowNodes.length-1 
    tempArr = split(objRowNodes(i).text) 
    msgbox "second last: "&tempArr(ubound(tempArr)-1)&vbcrlf&_ 'Displays the 2nd last column data 
      "last: "&tempArr(ubound(tempArr))      'Displays the last column data 
next 

出力:

enter image description here

enter image description here

+0

完璧に動作します - ありがとう!シンプルでエレガント。私は微調整のカップルと私は自分のスクリプトにそれを適応させることができます。ありがとうございました。解決策として受け入れる。 – Sparcx

+0

うれしかった:) – Gurman

関連する問題