nijawang wrote:
發現網頁好像有改版,網址有變


[點擊下載]
nijawang wrote:
發現網頁好像有改版,網址有變


snare wrote:
.AsTable.ToExcel...(恕刪)
Morten Hsu wrote:
可不可以再選擇起始日期和結束日期?還有,使用chrome.FindElementsByXPath抓取資料,好像過一段時間XPath就會做個小變動,用起來是有點不方便
Sub all_table()
Dim chrome As New Selenium.ChromeDriver, UrL As String, stock As String, table, R As Integer, C As Integer, i As Integer, TempArray
Dim keys As New Selenium.keys
stock = InputBox("股票代號", , 2330)
Sheets("工作表1").Cells.Clear
R = 1: C = 1
UrL = "https://goodinfo.tw/tw/ShowMarginChart.asp?STOCK_ID=" & stock
chrome.Get UrL
chrome.Wait 6000
'day1
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").Clear
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys "2024"
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys (keys.Tab)
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys "08"
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys "08"
'day2
chrome.FindElementByXPath("//*[@id='edtEND_DT']").Clear
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys "2024"
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys (keys.Tab)
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys "09"
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys "09"
'close ad
chrome.FindElementByXPath("/html/body/div[5]/button").Click
'click Query button
chrome.FindElementByXPath("//*[@id='divMarginDetailData']/table/tbody/tr/td/table/tbody/tr/td[1]/nobr[3]/input[3]").Click
chrome.Wait 6000
Set table = chrome.FindElementsByTag("table")
For i = 1 To table.Count
R = R + 1
TempArray = table(i).AsTable.Data
Sheets("工作表1").Cells(R, C).Value = "****** Table " & i & "******"
If (UBound(TempArray) * UBound(TempArray, 2)) > 0 Then
Sheets("工作表1").Cells(R + 1, C).Resize(UBound(TempArray), UBound(TempArray, 2)).Value = TempArray
End If
R = R + UBound(TempArray) + 1
DoEvents
Next i
chrome.Quit
Set chrome = Nothing
End Sub
Sub one_table()
Dim chrome As New Selenium.ChromeDriver, UrL As String, stock As String, table, TempArray
Dim keys As New Selenium.keys
stock = InputBox("股票代號", , 2330)
Sheets("工作表1").Cells.Clear
UrL = "https://goodinfo.tw/tw/ShowMarginChart.asp?STOCK_ID=" & stock
chrome.Get UrL
chrome.Wait 6000
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").Clear
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys "2024"
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys (keys.Tab)
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys "08"
chrome.FindElementByXPath("//*[@id='edtSTART_DT']").SendKeys "08"
chrome.FindElementByXPath("//*[@id='edtEND_DT']").Clear
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys "2024"
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys (keys.Tab)
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys "09"
chrome.FindElementByXPath("//*[@id='edtEND_DT']").SendKeys "09"
chrome.FindElementByXPath("/html/body/div[5]/button").Click
chrome.FindElementByXPath("//*[@id='divMarginDetailData']/table/tbody/tr/td/table/tbody/tr/td[1]/nobr[3]/input[3]").Click
chrome.Wait 6000
Set table = chrome.FindElementsByTag("table")
TempArray = table(22).AsTable.Data
Sheets("工作表1").Cells(1, 1).Resize(UBound(TempArray), UBound(TempArray, 2)).Value = TempArray
chrome.Quit
Set chrome = Nothing
End Sub
snare wrote:[點擊下載]...(恕刪)感謝snare的指導與範例提供!
nijawang wrote:
後來自己用了array()來抓Json資料,不然History資料很多會很慢。






Morten Hsu wrote:
非常感謝Snare大...(恕刪)