我(在Excel中,VBA)将导航到此网页:
http://www.nordea.dk/wemapp/currency/dk/valutaKurser
复制报价。但是,我想删除所有的费率,只添加我的子需要的。
要做到这一点,我需要检查所有的框(在表格的左侧),但框的数量不是恒定的 - 所以我不能硬编码框的名称。
我想一种方法是提取整个html,确定行数,然后循环。但它似乎非常不方便。当然有一些更简单的方法,需要更少的代码和更少的存储空间?
答案 0 :(得分:1)
您可以Split()
vbNewLine
对该表进行Function FirstRow(myArray() As String, Optional curr As String) As Long
If curr = "" Then
curr = "*[A-Z][A-Z][A-Z]/[A-Z][A-Z][A-Z]*"
Else
curr = "*" & curr & "*"
End If
For i = LBound(myArray) To UBound(myArray)
If myArray(i) Like curr Then 'FX denoted as "XXX/XXX"
FirstRow = i
Exit Function
End If
Next i
End Function
Sub ert()
Dim myArray() As String, URLStr As String
URLStr = "http://www.nordea.dk/wemapp/currency/dk/valutaKurser"
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.Navigate URLStr
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
On Error GoTo Err:
Data = ie.Document.body.innerHTML 'innerText
If False Then
Err:
Data = ie.Document.body.innerHTML
End If
myArray = Split(Data, "<tr>") 'vbNewLine) 'vbCrLf)
'For i = LBound(myArray) To UBound(myArray)
' Cells(i + 1, 1).Value2 = myArray(i)
'Next
Dim curr() As String
ReDim curr(2)
curr(0) = "DKK/NOK"
curr(1) = "EUR/SEK"
curr(2) = "USD/CHF"
For i = LBound(curr) To UBound(curr)
x = FirstRow(myArray, curr(i)) - FirstRow(myArray) + 1
MsgBox "table:body:rows:" & x & ":cells:1:cell:check"
Next i
ie.Quit
Set ie = Nothing
End Sub
并在该行的每一行中搜索该货币(介意标题)。
由于输入的名称类似于 table:body: rows:2 :cells:1:cell:check 您可以将货币与复选框匹配。
在实践中它看起来像(直到获取元素名称):
vbNewLine
对不起,library(data.table)
library(plyr) # For revalue
set.seed(123098)
my_table <- data.table(x=1:10, str=sample(letters[1:4], 10, replace=T))
my_table[, y := 3*x + runif(nrow(my_table))] # Runs silently
mapping <- c("a"="andrew", "b"="barbarian", "c"="constant", "d"="deft")
my_table[, new_str := revalue(str, replace=mapping)] # Runs silently
some_condition <- TRUE
if(some_condition) {
my_table[, y := 3*x + runif(nrow(my_table))] # Runs silently
my_table[, new_str := revalue(str, replace=mapping)] # Why does this print?
}
这次不会削减它,我的不好。另外,检查一个命名的元素不应该那么难,如果你提供了你的snipplet来检查所有的盒子我甚至会给它一个镜头。