- ©«¤l
- 354
- ¥DÃD
- 5
- ºëµØ
- 0
- ¿n¤À
- 387
- ÂI¦W
- 0
- §@·~¨t²Î
- windows7
- ³nÅ骩¥»
- vba,vb,excel2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2017-1-8
- ³Ì«áµn¿ý
- 2024-8-2
|
¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-9-24 13:37 ½s¿è
Sub ¤À¸Ñ¨BÆJª©()
Cells.ClearContents
Set driver = CreateObject("Selenium.ChromeDriver")
driver.AddArgument ("headless") 'µLÀYµøµ¡
driver.Wait 1500
driver.get "https://mis.twse.com.tw/stock/group.jsp?type=fixed&ex=tse&ind=TIDX#STATISTICS"
Set tbl6 = driver.findelementsbytag("table")(6)
Set tby1 = tbl6.findelementsbytag("tbody")(1)
Set tr2 = tby1.findelementsbytag("tr")(2)
Set td2 = tr2.findelementsbytag("td")(3)
Cells(1, 1) = td2.Text
End Sub
Sub ¤@®ð¨þ¦¨ª©()
Cells.ClearContents
Set driver = CreateObject("Selenium.ChromeDriver")
driver.AddArgument ("headless") 'µLÀYµøµ¡
driver.Wait 1500
driver.get "https://mis.twse.com.tw/stock/group.jsp?type=fixed&ex=tse&ind=TIDX#STATISTICS"
Cells(1, 1) = driver.findelementsbytag("table")(6). _
findelementsbytag("tbody")(1). _
findelementsbytag("tr")(2). _
findelementsbytag("td")(3). _
Text
End Sub
'¨âºØ¼gªk³£¤@¼Ë
'¦pªGn¥[¤W§¹¥þ¦Û°Ê§ó·s
Sub Chrome§ó·s®É¦Û°Ê§ó·s_and_¤À¸Ñ¨BÆJª©()
Do
On Error GoTo 0
On Error Resume Next
Set driver = CreateObject("Selenium.ChromeDriver")
driver.AddArgument ("headless")
Err = 0
driver.Start
If Err <> 0 Then
If Exit5 > 5 Then Exit Sub 'Y°õ¦æ¶W¹L5¦¸´N¤£¶]¤F
driver.Quit
Set driver = Nothing
Exit5 = Exit5 + 1
Call updataSelenium
End If
Loop Until Err = 0
Set driver = Nothing
Cells.ClearContents
Set driver = CreateObject("Selenium.ChromeDriver")
driver.AddArgument ("headless") 'µLÀYµøµ¡
driver.Wait 1500
driver.get "https://mis.twse.com.tw/stock/group.jsp?type=fixed&ex=tse&ind=TIDX#STATISTICS"
Cells(1, 1) = driver.findelementsbytag("table")(6). _
findelementsbytag("tbody")(1). _
findelementsbytag("tr")(2). _
findelementsbytag("td")(3). _
Text
End Sub
Sub updataSelenium() '¦pªG¤¤³~´N¸õÂ÷ ¥i¯à¬OÀɮצì¸mn«·s½T»{ ©ÎªÌ ª©¥»ÀɮרS§R°£¾ÉPµ{§ÇµLªk°õ¦æ ¤]¥i¯à¬OÀ£ÁYÀɸÑÀ£¹Lµ{¥X°ÝÃD ¤]¥i¯à¬O¤U¸üÀÉ®×¥X°ÝÃD ¥DnF8³v¨B¬Ýþ¬q¸õÂ÷
'§ä¨ìchromedriverªºÀɮצì¸m ¦³ªº¹q¸£¦ì¸m¤£¦P ³q±`¬O³o¨âÓ¦ì¸m¨ä¤@
'½T»{chromedriver¥¿½TªºÀɮ׸ô®| »P¥¿½Tªº¸ê®Æ§¨¸ô®|
path1 = "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\Chromedriver.exe"
path2 = "C:\Program Files\SeleniumBasic\chromedriver.exe"
If Dir(path1) <> "" Then TempDrvFile = path1
If Dir(path2) <> "" Then TempDrvFile = path2
foler = Left(TempDrvFile, InStrRev(TempDrvFile, "\"))
'¬d§ä¹q¸£·í«eªºgoogleª©¥»¸¹
Set objHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0") 'Get chrome version
chrversion = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon\version")
dotsarr = Split(chrversion, ".")
leftchrver = dotsarr(0) & dotsarr(1)
'¬d§ä¹q¸£·í«eªºchromeDriverª©¥»¸¹
Set oShell = CreateObject("wscript.shell")
errcode = oShell.Exec(TempDrvFile & " --version").StdOut.ReadAll
verarr = Split(errcode, " ")
chrdrv = verarr(1)
dotsarr2 = Split(chrdrv, ".")
leftchrdrv = dotsarr2(0) & dotsarr2(1)
If leftchrver = leftchrdrv Then Exit Sub
'Y¤£²Å ,«h¤W©xºô¬d³Ì·schromeDriverª©¥»¸¹
Url = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & dotsarr(0)
Call objHttp.Open("GET", Url, False)
Call objHttp.Send("")
version_number = objHttp.responseText
dotsarr3 = Split(version_number, ".")
leftversion_no = dotsarr3(0) & dotsarr3(1)
download_url = "https://chromedriver.storage.googleapis.com/" + version_number + "/chromedriver_win32.zip"
'§Q¥Î³Ì·sªºchromeDriverª©¥»¸¹ §ä¨ì¤U¸ü¸ô®|
Call objHttp.Open("GET", download_url, False)
Call objHttp.Send("")
'¤U¸üÀÉ®×,¨Ã§ó¥¿¦¨À£ÁYÀÉ°ÆÀɦW
Set fileStream = CreateObject("ADODB.Stream")
With fileStream
.Open
.Type = 1 'adTypeBinary
.Write objHttp.responseBody
.Position = 0
.SaveToFile foler & "chromedriver.zip", 2
.Close
End With
'¸ÑÀ£ÁY(¸ÑÀ£«eµ{§Ç·|¥ý§R±¼Âªº)
On Error GoTo 0
Set oApp = CreateObject("Shell.Application")
If Dir(TempDrvFile) <> "" Then Kill TempDrvFile
oApp.Namespace(foler).CopyHere _
oApp.Namespace(foler & "chromedriver.zip").items
End Sub |
|