目前,我有以下宏加載網頁:需要拉一個網頁的特定選項值VBA宏
Sub OOS_Query()
'This together with the True value at the end will tell the macro to not update the screen until it reaches a point that I want it to show updates again
Application.ScreenUpdating = False
ActiveWorkbook.Connections("Connection1").Delete
Sheet2.Range("A:C").Clear
With Sheet2.QueryTables.Add(Connection:= _
"URL;http://[ommitted on purpose]id=42908", Destination:=Sheet2.Range("$A$1"))
.FieldNames = True
.PreserveFormatting = True
.RefreshOnFileOpen = True
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.RefreshPeriod = 5
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1,2"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
Application.ScreenUpdating = True
End Sub
正如你所看到的網頁有一個「id」值是不斷變化的,因爲它查詢數據庫。該值看起來網頁的來源如下:
Date <select name="id">
<option value='43032' >2017-05-13 05:00:01</option>
<option value='43031' >2017-05-13 04:45:02</option>
<option value='43030' >2017-05-13 04:30:01</option>
<option value='43029' >2017-05-13 04:15:02</option>
...
<option value='43004' >2017-05-12 22:00:01</option>
我正在尋找一種方式來在代碼集成到能夠拉動網站與任何ID它有,只要時間在21:58:00和22:02:00之間;無論當前日期是什麼。通常的做法是訪問網站並從下拉菜單中選擇我們想要查詢的日期/時間,然後將網站粘貼到上面的代碼部分。
如果我可以自動做到這一點,它將消除我必須每天編輯代碼。
在此先感謝!
忘了補充說,不選擇22:00:01的網站顯示時間的原因,是因爲它有時會改變。 – Jahir
是從DOM還是XHR取得的HTML代碼片段? – omegastripes
@omegastripes它將是DOM。 – Jahir