2017-03-05 61 views
-1

我試圖從本網站使用VBA格式文本的元素名稱在此代碼我想在VBA擅長

<div class="train-logo 
     train-logo-monochrome 
     train-logo--trenitalia-monochrome 
     train-logo--frecciarossa-monochrome" title="Trenitalia"> 
    </div> 

VBA提取,提取元素的網頁標題:

For Each treno In IE.Document.getelementsbytagname("div") 
    If treno.getattribute("title") Then 
     Cells(rownumber2, "u").Value = treno.innertext 
+1

你是怎麼做到的,當你運行你的代碼時會發生什麼? –

+0

我已經開發了一個關於excel的宏,這個宏轉換爲互聯網開採者並且以價格爲例來獲取元素。在這種情況下,我想從格式文本獲得標題=「trenitalia」https://www.trainline.eu/search/milano/firenze/2017-03-21-14:00 – cory

+0

如果您有代碼,最好將它包含在你的問題中,否則它可能會被關閉。 –

回答

0

東西像這應該工作:

Dim treno, t 

For Each treno In IE.Document.getelementsbytagname("div") 
    t = treno.getattribute("title") 
    If t <> "" Then Cells(rownumber2, "u").Value = t 
Next treno 

這不是從你的問題說明你需要多少,這些從頁面改爲:如果只有一個你可以Exit For獲得價值後。

+0

宏運行但不要粘貼價值標題的細胞再次閱讀網頁 – cory

+0

非常感謝蒂姆威廉姆斯 – cory