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

[µo°Ý] ¦bºô­¶©â¨ú¸ê®Æ®É¹J¨ì¡u¨S¦³¨Ï¥ÎÅv­­¡vªº°ÝÃD

[µo°Ý] ¦bºô­¶©â¨ú¸ê®Æ®É¹J¨ì¡u¨S¦³¨Ï¥ÎÅv­­¡vªº°ÝÃD

¥»©«³Ì«á¥Ñ ¤p«L«È ©ó 2016-12-8 10:33 ½s¿è

¥H¤U¬O§Ú¦bºô¯¸©â¨ú¸ê®Æ®É¥ÎªºCODE
  1. Sub test()
  2. Dim http As Object, i As Integer

  3. Set http = CreateObject("InternetExplorer.Application")

  4. With http

  5. For i = 1 To 100

  6.     .Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"
  7.     .Visible = True
  8.     Do While .readyState <> 4
  9.         DoEvents
  10.     Loop
  11.    
  12.     .document.getelementbyid("ddlShareholdingDay").Value = 30
  13.     .document.getelementbyid("ddlShareholdingMonth").Value = 11
  14.     .document.getelementbyid("ddlShareholdingYear").Value = 2016
  15.     .document.getelementbyid("txtStockCode").Value = Format(Cells(i, 1), "00000")
  16.     .document.getelementbyid("btnSearch").Click
  17.    
  18.    
  19.     Do Until InStr(.document.body.innerhtml, "pnlResult") > 0
  20.         DoEvents
  21.     Loop
  22.     Set A = .document.getelementbyid("pnlResult")

  23.     Do Until InStr(result, "Remarks:") > 0
  24.     DoEvents
  25.     result = A.innerhtml
  26.     Loop

  27. Debug.Print Cells(i, 1)

  28. Next i

  29. End With

  30. End Sub
½Æ»s¥N½X
³Ìªì¹B¦æ¬O¨S¦³°ÝÃD¡A¦ý·í§ÚªºLOOPING¦æ¤F¤Q¦h¦¸«á¡A§Ú´N·|¹J¨ìERROR¡A»¡§Ú¡u¨S¦³¨Ï¥ÎÅv­­¡v¡AµM«áµ{¦¡«K¦b¡uSet A = .document.getelementbyid("pnlResult")¡v°±¤î¡C¦pªG§Ú¦b¦¹®É«öF8¡Aµ{¦¡¬O¥i¥HÄ~Äò¹B¦æ¡C
©ó¬O§Ú¦b·Q¬O¤£¬O¦]¬°§Úªº¤W¤@¥y¡G¡u.document.getelementbyid("btnSearch").Click¡v¡Aºô­¶redirect¨ìµ²ªGºô­¶¡A»Ý­n®É¶¡²£¥Íhtml code¡A¾É­P§Ú¦æ set A¨º¤@¥y®É¡Aºô­¶ÁÙ¨S¦³pnlResultªºitem¡C©ó¬O§Ú«K¥[¤W¤F¡G
  1.     Do Until InStr(.document.body.innerhtml, "pnlResult") > 0
  2.         DoEvents
  3.     Loop
½Æ»s¥N½X
¥ýÀˬdhtml code¤¤¦³¨S¦³¡upnlResult¡v¤~set A¡A¥i¬O°ÝÃD¤´µM¦s¦b¡A§Ú¤´µM»Ý­n¤H¤â­«±Òµ{¦¡¡C½Ð°Ý¦U¦ì¦³¨S¦³¤èªk¸Ñ¨M¡HÁÂÁ¤j®a¡C

test.zip (14.79 KB)

¦^´_ 1# ¤p«L«È
  1. Sub test()
  2.     On Error GoTo ErrorHandle
  3.     Dim http As Object, i As Integer
  4.    
  5.     Set http = CreateObject("InternetExplorer.Application")
  6.     With http
  7.         For i = 1 To 100
  8.             .Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"
  9.             .Visible = True
  10.             Do While .readyState <> 4: DoEvents: Loop
  11.             
  12.             .document.getelementbyid("ddlShareholdingDay").Value = 30
  13.             .document.getelementbyid("ddlShareholdingMonth").Value = 11
  14.             .document.getelementbyid("ddlShareholdingYear").Value = 2016
  15.             .document.getelementbyid("txtStockCode").Value = Format(Cells(i, 1), "00000")
  16.             .document.getelementbyid("btnSearch").Click
  17.             Do Until InStr(.document.body.innerhtml, "pnlResult") > 0
  18.                 DoEvents
  19.             Loop
  20.             Set A = .document.getelementbyid("pnlResult")
  21.             Do Until InStr(result, "Remarks:") > 0
  22.                 DoEvents
  23.                 result = A.innerhtml
  24.             Loop
  25.             
  26.             Debug.Print Cells(i, 1)
  27.         Next i
  28.     End With
  29.    
  30. Exit Sub
  31. ErrorHandle:
  32.     If Err.Number = 70 Then '¨S¦³¨Ï¥ÎÅv­­
  33.         Resume  'do nothing, back to error
  34.     Else
  35.         Debug.Print Err.Number, Err.Source, Err.Description
  36.         Stop    'F8 to debug problem
  37.         Resume
  38.     End If
  39. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¥»©«³Ì«á¥Ñ ¤p«L«È ©ó 2016-12-13 10:56 ½s¿è
¦^´_  ¤p«L«È
stillfish00 µoªí©ó 2016-12-8 13:45



    ¨S·Q¨ì­ì¨Ó¥i¥H¥ÎERROR HANDLINGªº¤èªk¡AÁÂÁ¤j¤j¡C¦ý§Ú¨Ï¥Îerror handle®É¦]¬°¤U­±ªº¤p°ÝÃD¦Ó¥X¿ù¡A©Ò¥H§Ú¥u¯à¥Îsleepªº¤èªk¡A¨S¦³¥Îerror handle
¤@­Ó¤p°ÝÃD¡A¦pªGµ{¦¡´M§ä¨S¦³¸ê®Æªº½s¸¹¡A¨Ò¦p¡G¡u820¡v¡Aºô­¶·|¦³pop-up msgbox»¡¡G¡uStock code 820 does not exist ... ¡v¡A©Ò¥H§Ú·Q¥ýÀˬdhtml¦³¨S¦³¡udoes not exist ¡vªº¦r²´¡A¦pªG¦³§Ú«K¸õ¨ì¤U¤@°¦¡C
¦ý¥i¯à¦]¬°pop-up msgboxªºÃö«Y¡A§Ú¤U¤@­Óloop¨«¨ì¡u.Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"¡v®É·|Åã¥Ü¡u-2147024726   VBAProject    'Navigate' ¤èªk ('IWebBrowser2' ª«¥ó) ¥¢±Ñ¡v
  1. Sub test()
  2. Dim http As Object, i As Integer

  3. Set http = CreateObject("InternetExplorer.Application")

  4. With http

  5. For i = 1 To 100

  6.     .Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"
  7.     .Visible = True
  8.     Do While .readyState <> 4
  9.         DoEvents
  10.     Loop
  11.    
  12.     .document.getelementbyid("ddlShareholdingDay").Value = 30
  13.     .document.getelementbyid("ddlShareholdingMonth").Value = 11
  14.     .document.getelementbyid("ddlShareholdingYear").Value = 2016
  15.     .document.getelementbyid("txtStockCode").Value = Format(Cells(i, 1), "00000")
  16.     .document.getelementbyid("btnSearch").Click

  17.    sleep 2000

  18.                 result = http.document.body.innerhtml
  19.                
  20.                 If InStr(result, "Network Error") > 0 Then
  21.                     MsgBox "Website error"
  22.                     GoTo out
  23.                 End If
  24.                
  25.                 If InStr(result, "does not exist OR not available for enquiry") > 0 Then
  26.                     GoTo nextd
  27.                 End If
  28.    
  29.     Do Until InStr(result , "pnlResult") > 0
  30.         DoEvents
  31.     Loop
  32.     Set A = .document.getelementbyid("pnlResult")
  33.    result = A.innerhtml

  34.     Do Until InStr(result, "Remarks:") > 0
  35.     DoEvents
  36.     result = A.innerhtml
  37.     Loop

  38. Debug.Print Cells(i, 1)

  39. Next i

  40. End With

  41. End Sub
½Æ»s¥N½X
½Ð°Ý¦³¨S¦³¤èªkÃö±¼IEªºpop-up msgbox¡HÁÂÁÂ

TOP

¦^´_ 3# ¤p«L«È

¸Õ¸Õ¬Ý 2003, XP, IE8 ¤U:¨S¦³Åv­­ªº°ÝÃD
  1. Option Explicit
  2. Sub EX_IE«ö¤UEnter()
  3.     Dim http As Object, i As Integer, A As Object, Result As String
  4.     Set http = CreateObject("InternetExplorer.Application")
  5.     With http
  6.         .Navigate "http://www.hkexnews.hk/sdw/search/search_sdw.asp"
  7.         '.Visible = True
  8.         For i = 1 To 100
  9.             Do While .readyState <> 4 Or .Busy:         DoEvents:    Loop
  10.             .document.getelementbyid("ddlShareholdingDay").Value = 30
  11.             .document.getelementbyid("ddlShareholdingMonth").Value = 11
  12.             .document.getelementbyid("ddlShareholdingYear").Value = 2016
  13.             .document.getelementbyid("txtStockCode").Value = Format(Cells(i, 1), "00000")
  14.             .document.getelementbyid("btnSearch").Click
  15.             Do While .readyState <> 4 Or .Busy:
  16.                 DoEvents
  17.                 If .Busy Then
  18.                     .document.Focus
  19.                     DoEvents
  20.                     Application.SendKeys "{ENTER}", True   '**«ö¤UÁä
  21.                 End If
  22.             Loop
  23.             Result = ""
  24.             Do Until InStr(Result, "pnlResult") > 0
  25.                 Result = .document.body.innerhtml
  26.                 If Len(Result) > 0 Then
  27.                     Cells(i, 2) = IIf(InStr(Result, "pnlResult") > 0, "OK", "Not Exist")
  28.                     If InStr(Result, "pnlResult") = 0 Then GoTo Next_StockCode
  29.                 End If
  30.             Loop
  31.             Set A = .document.getelementbyid("pnlResult")
  32.             Do Until InStr(Result, "Remarks:") > 0
  33.                 DoEvents
  34.                 Result = A.innerhtml
  35.             Loop
  36. Next_StockCode:
  37.         Next i
  38.         .Quit
  39.     End With
  40.     MsgBox "OK"
  41. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

        ÀR«ä¦Û¦b : §ïÅܦۤv¬O¦Û±Ï¡A¼vÅT§O¤H¬O±Ï¤H¡C
ªð¦^¦Cªí ¤W¤@¥DÃD