ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

¶}µoªÌ¤u¨ãselenium+vba¥Î©óºô­¶§ì¨ú¸ê®Æªº°ÝÃD

¶}µoªÌ¤u¨ãselenium+vba¥Î©óºô­¶§ì¨ú¸ê®Æªº°ÝÃD

¥Ø«eµ{¦¡¥i¥H¥¿±`¹B¦æ
·Q°Ý´X­Ó³¡¤À°ÝÃD
1.¦pªG§Ú¤£¥Îsendkeyªº¤è¦¡,¥i§_¥¿±`ªº±Nºô­¶·í«e­¶­±ªº©Ò¦³¸ê®Æ¥þ³¡½Æ»s¨ì¤u§@ªí¤W?
¦pªG¤£¦æ,¥i§_ª½±µ§ì¨úºô­¶¤W¾ã­Óªí®æ¸ê®Æ?¦Ó¤£¥Î°j°é¤@­Ó¤@­Ó¶×¤J,·|«ÜºC

2.ºô¸ô¤W¦³¬d¸ß¨ì¥i¥H¤£¥Î¶}±Òºô­¶,´N¯à­I´º¹B¦æ§ì¸ê®Æªº¤è¦¡,¤£ª¾¹D¬O§_¯à¦¨¥\?


¥Ñ©ó¥vµÜ©iselenium§ïª©¦Ü¤µ,¦n¹³¼gªk¤]¦³ÅܤÆ
ºô¸ô¤W³\¦hªº¶}±Ò¤è¦¡¤w¸gµLªk¥¿±`¹B¦æ
¤p§Ì­n§ìªºÀɮ׬O¤½¥q¤º³¡ªºchromeºô­¶,©Ò¥H±o¾a³o­Ó¤èªk
½d¨Ò¨Ï¥Îyahoo¤ôªdªÑ²¼ªº¸ê®Æ¨Ó´ú¸Õ
¦³ªº¹q¸£¥i¯à·|§ì¤£¨ì¸ê®Æ
«Øij¦b¥d¦íªº¦a¤è¥[¤Wdrive.waite 3000   '3000´N¬O¤T¬í
¹ê»Ú¤W§Ú·|¥Î¤¸¯À¥Í¦¨§@¬°¥[¸ü§¹¦¨ªº§PÂ_,¥H§Kºô­¶©|¥¼¥[¸ü§¹¦¨´N¦b½Æ»s
  1.     Dim driver As Selenium.ChromeDriver


  2. Sub yahoo()
  3. Application.ScreenUpdating = False  '°±¤î¿Ã¹õ§ó·s
  4. Application.DisplayAlerts = False  '°õ¦æ§R°£«e¥ý¼È®É°±¤îĵ§i°T®§¡A°õ¦æ§¹¶·«ì´_ĵ§i°T®§¡C
  5. On Error Resume Next


  6. Sheets("¤ëªí¤U¸ü°Ï").Select
  7. Sheets("¤ëªí¤U¸ü°Ï").Range("A:P").Select
  8. Selection.ClearContents


  9. Set driver = CreateObject("Selenium.ChromeDriver")  '±Ò°Êselenium

  10. URL = "https://tw.stock.yahoo.com/s/list.php?c=%A4%F4%AAd&rr=0.76405700%201556514294"
  11. driver.Get URL

  12. driver.Wait 1000
  13. SendKeys "^{a}"    '¥þ¿ï
  14. driver.Wait 500
  15. SendKeys "^{c}"     'copy
  16. driver.Wait 1000

  17. Sheets("¤ëªí¤U¸ü°Ï").Select
  18. Sheets("¤ëªí¤U¸ü°Ï").Range("a1").Select
  19. ActiveSheet.PasteSpecial Format:="HTML", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True  '¥Î¯Â®æ¦¡¶K¤W
  20. driver.Wait 1000
  21. driver.Quit 'µ²§ôselenium
  22. Application.DisplayAlerts = True '°õ¦æ§R°£«e¥ý¼È®É°±¤îĵ§i°T®§¡A°õ¦æ§¹¶·«ì´_ĵ§i°T®§¡C
  23. Application.ScreenUpdating = True
  24.     End Sub
½Æ»s¥N½X

yahoo¤ôªdtest.rar (31.27 KB)

https://stackoverflow.com/questions/38613307/using-selenium-vba-bringing-the-cell-values-from-a-dynamic-web-page-table-to-exc
¦pªG¥u¬O³æ¤@¤¸¯À©ÎªÌ³æ¤@­Èªº³¡¤À§Ú¯à°÷³B²z
¦ý¬O·í¸ê®Æ¬°ªí®æª¬ªp®É,¸ê®Æ¶q¤Ó¦h,¤@­Ó¤@­Ó³B²z©ÎªÌ¥h§ì¦³ÂI¤Ó²Ö
§Ú¥i¥H¥ý¥þ³¡¥á¨ìexcel¤º§Ú¦bºCºC³B²z,¤]¤ñ¸û¦n¼g...

¤j³¡¤À³£¥ÎÃþ¦ü³oºØªºÂù°j°é§ìªí®æ
¥u¬O¦³ÂIºC...
·Q»¡§Q¥Î°Å¶K諸¤è¦¡ª½±µ¥þ³¡¶K¤W
¦]¬°§Ú¦³ªºªí®æ´X¸U¦C....
For Each posts In driver.FindElementsByXPath("//table[contains(@class,'daen-report')]")
    For Each post In posts.FindElementsByXPath(".//tr")
        For Each t_data In post.FindElementsByXPath(".//td[@class='row-odd']|.//td")
        y = y + 1
        Cells(x, y) = t_data.Text
        Next t_data
        x = x + 1
        y = 0
    Next post
Next posts

¦Ó§Ú­ì¥ý¥Îªº´N¬OÃþ¦ü³oºØªº
https://stackoverflow.com/questions/23992826/vba-ctrla-to-select-all-content-in-a-page-by-selenium-webdriver
¦ý¦]¬°¦bµ{¦¡°õ¦æ¤¤
¦pªGÂIÀ»¤FÂsÄý¾¹©ÎªÌ¥ô¦óÀɮ׸ê®Æ§¨
ºô­¶¸òexcelªº±Ò¥Îª¬ºA·|®ø¥¢
·|¾É­PÁä½L¾Þ±±¥h½Æ»s¨ì¿ù»~ªº¦a¤è

¹³excel vba¥»¨­¦n¹³¦³
ie.ExecWB 17,1'// SelectAll
ie.ExecWB 12,2'//½Æ»s¿ï¾Ü
ªº¤è¦¡....

Ãö©ó«á»O¶}±Ò
https://stackoverflow.com/questions/16180428/can-selenium-webdriver-open-browser-windows-silently-in-background

https://stackoverflow.com/questions/48597592/how-to-make-selenium-chromedriver-run-headlessly-in-vba

https://stackoverflow.com/questions/42801833/how-to-run-chrome-driver-in-headless-mode-or-in-background

https://stackoverflow.com/questions/44028584/run-selenium-without-wrapper-installed

TOP

¥»©«³Ì«á¥Ñ joey0415 ©ó 2019-4-30 18:44 ½s¿è

https://www.udemy.com/complete-web-automation-with-excel-vba/

³o½Òµ{¥u­n360¤¸
§A¦Ò¼{¤@¤U
§Ú¦Û¤v¦³¶R
À³¸Ó¬O§A­nªºµª®×
¦pªG§A­n§Ö¤@ÂI
°ò¥»¤W¥u¯à¥Îxmlhttp¤è¦¡¤~¯à¸Ñ¨M

TOP

        ÀR«ä¦Û¦b : ¤@¥y·Å·xªº¸Ü¡A´N¹³©¹§O¤H¨­¤WÅx­»¤ô¡A¦Û¤v·|ªg¨ì¨â¤Tºw¡C
ªð¦^¦Cªí ¤W¤@¥DÃD