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

[µo°Ý] [EXCEL VBA] ³oºô­¶«ç»ò§ì©O?

[µo°Ý] [EXCEL VBA] ³oºô­¶«ç»ò§ì©O?

¥»©«³Ì«á¥Ñ Hunt01 ©ó 2016-1-4 15:57 ½s¿è

¤j®a¦n

    ¤p§Ì VBA ¤@¸ô¾Ç¨Ó¡A©l²×¸Ì¸Ì¸¨¸¨¡A¦Ñ¬O§ì¤£¨ì­n»â
    ²{¦b¤p§Ì§Æ±æ½m²ß§ì¥H¤Uºô­¶¡A±N¤§¤U¸ü¦¨ªí¡C
    ¥i¬O.....¸Ô²Ó¸ê®Æ¨ºÄ檺³sµ²­n«ç»ò§ì©O?
    ¦U¦ì±M®a¤j­Y¤£©ö»¡©ú¡A²³æ´£ÂI¤@¤U°Ñ¦Ò¨º¨Ç¸ê®Æ©ÎÃöÁä¦r¡A¥ç¤Q¤À·P¿E¡A¤p§Ì·|¥Î¤ß¥h§ä¸ê®Æªº
    ÁÂÁ¤j®a!!

ºô§}: http://mops.twse.com.tw/mops/web/t05sr01_1
µe­±:

¦^´_ 1# Hunt01

http://club.excelhome.net/thread-874608-1-1.html

³o¤èªk¥ÎÂIÀ»ªk¡A½Âà§ó­±«á¡A±N­¶­±°O¿ý¤U¨Ó

¥t¥~¤@ºØ¬O
http://club.excelhome.net/thread-1159783-1-1.html

xmlhttpªk¡A§ä¨ìpost¸ê®Æ§ì¤U¨Ó¤ÀªR

§Ú¦Û¤v¸Õ¼g¤Fªá¤F¦nªø¤@¬q®É¶¡¤~¼g¥XÃþ¥Xªº¤º®e

TOP

¥»©«³Ì«á¥Ñ Hunt01 ©ó 2016-1-5 22:47 ½s¿è

¦^´_ 2# joey0415

¤Q¤À·PÁ joey0415 ¤j!
¤p§Ì¿³¾Ä¦a«e©¹³sµ²¡Aµ²ªG¤JÄ_¤s¡AªÅ¤â¦^¡AÊj~~
­ì¦]¬O¸ÓÄ_¤s¤Ó±j¤j¡A¾ã®yª÷¤s¡A¦ý¤p§Ì®zÂû¤@­Ó¡A°£¤Fª÷¥ú°{°{¦n¨ë²´¡A±µ¤U¨Ó´N¦³¬Ý¨S¦³À´¡AºV¤£¤U¥b­Óª÷®h...

§Ú­J¶Ã¤ñ¹º¦a¸ÕµÛ¥Î joey0415 ¤j©Ò«Øijªº xmlhttp ªk¡A§ä¨ì post ¸ê®Æ§ì¤U¨Ó¤ÀªR¡C­º¥ý¥Î Fiddler ±N¸ê®Æ§ì¤U¨Ó¤ÀªR¡AFiddler §ì¥X¨Óªº½X¬Ý¨Ó»P­ì©lºô­¶½X¬Ûªñ¡A¥i¯à¬OÆ[´ú¯¸ªº¸ê®Æ¸û²³æªºÃö«Y§a¡C

§Ú¥HÂE®ü¬°¨Ò¡A¥¦ªº­ì©l½X¦p¤U:

<td style='text-align:left !important;' nowrap>ÂE®ü</td>
<td style='text-align:left !important;'>105/01/05</td>
<td style='text-align:left !important;'>11:41:00</td>
<td style='text-align:left !important;'>»¡©ú´CÅé³ø¾É</td>
<td><input type='button' value='¸Ô²Ó¸ê®Æ' onclick="document.fm_t05sr01_1.SEQ_NO.value='1';document.fm_t05sr01_1.SPOKE_TIME.value='114100';document.fm_t05sr01_1.SPOKE_DATE.value='20160105';document.fm_t05sr01_1.COMPANY_NAME.value='?E??';document.fm_t05sr01_1.COMPANY_ID.value='2317';document.fm_t05sr01_1.skey.value='2317201601051';document.fm_t05sr01_1.hhc_co_name.value='?E??';ajax1(this.form,'table01');">


¬Ý°_¨Ó¬O javascript(§Ú¤]¤£À´¡AÊj)?
«ç»ò¥Î vba ¨Ó³B²z³o¦n¥ûªº­ì©l½X©O?

ÁÂÁ¤j¤j­Ì¸Ñµª®z®zªº¤p§Ì

TOP

¦^´_ 3# Hunt01
onclick «á³]©w¤F¤@°ï­È¡AµM«á©I¥s ajax1
§A­n¤ÀªR´N­n¦A¥h§äºô­¶¤¤ªº³o­Ó ajax1 functionªº¤º®e
¥¦¸Ì­±·|¦A¦V¥t¤@­Óºô­¶POST½Ð¨D¡Apost °Ñ¼Æ¨Ó¦Û­è­è³]©w¨º¨Ç­È¡C
©Ò¥H§A­n±q
"document.fm_t05sr01_1.SEQ_NO.value='1';document.fm_t05sr01_1.SPOKE_TIME.value='114100';document.fm_t05sr01_1.SPOKE_DATE.value='20160105';document.fm_t05sr01_1.COMPANY_NAME.value='?E??';document.fm_t05sr01_1.COMPANY_ID.value='2317';document.fm_t05sr01_1.skey.value='2317201601051';document.fm_t05sr01_1.hhc_co_name.value='?E??';ajax1(this.form,'table01');"

³o¦r¦ê¤¤´£¨ú¥X§A­nªº°Ñ¼Æ¡A¦A¥Î xmlhttp ¦V¥t¤@­Óºô­¶POST½Ð¨D¡A
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¥»©«³Ì«á¥Ñ Hunt01 ©ó 2016-1-11 17:16 ½s¿è

«D±`·PÁ joey0415 ¥H¤Î stillfish00 ¤j¤jªº«ü¾É :$
¤p§Ì§Q¥Î¤W¶g¤Î°²¤é­J¶ÃºN¯Á¡Aªì¨B¥u¤j·§·|¥Î onclick ¨Ó¹F¨ì¥Øªº, xmlhttp «áÄò¦A±µ¦AÀy¡C
¤£¹L©_©Çªº¬O¡A¤p§Ì VBA click ®É¡A¦n¹³·|¦]¬°ºô­¶ refresh ¤£¤Î¦Ó³y¦¨«áÄò§ì¨ú¸ê®Æ¨BÆJ²£¥Í¿ù»~¡C§Ú¦³¥[¤J do loop ¨Óµ¥«Ý¡A¤£¹L¬Ý¨Ó³o­Ó do loop µL§@¥Î¡C
¤j¤j­Ì¦³«Øijªº³B²z¤èªk¶Ü?
ªþ¤W¤p§Ì©å¦Hªº code ¨Ñ°Ñ¦Ò¡C
ÁÂÁ¤j®a!!!!

Dim IE As New InternetExplorer
    IE.Visible = True

'­«¤j°T®§¤½§Gºô­¶
    IE.Navigate "http://mops.twse.com.tw/mops/web/t05sr01_1"
    Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
    Set doc = IE.document

'«ö¤U"¸Ô²Ó¸ê®Æ" button   
    Set docinput = doc.getElementsByTagName("input")
    r = 1
    For i = 0 To docinput.Length - 1
        If docinput(i).Value = "¸Ô²Ó¸ê®Æ" And docinput(i).Type = "button" Then

'???«ö¤U"¸Ô²Ó¸ê®Æ"button, ¦³®É¦³°ÝÃD???
            docinput(i).Click

            Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE

'¶i¤J"¸Ô²Ó¸ê®Æ"­¶­±«á¡A¶}©l§ì¨ú¥D­n¤º®e¡C¥D­n°T®§¤º®e¬° table(9)
            Set A = doc.getElementsByTagName("table")(9)
            Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
                        
'±N¥D­n°T®§¤º®e©ñ¤J sheet
            For j = 1 To A.Rows(4).Cells.Length - 1
                Sheets(1).Cells(r, j + 1).Select
                Sheets(1).Cells(r, j + 1).Value = A.Rows(4).Cells(j).innerText
            Next j
            r = r + 1

'§ì§¹°T®§¤º®e«á¡Aªð¦^¤W¤@­¶
            For Each img In doc.getElementsByTagName("img")
                If img.href = "http://mops.twse.com.tw/mops/web/images/bu_05.gif" Then

'???img.click ¦³®ÉµL°Ê§@???
                    img.Click

                    Do: DoEvents: Loop Until IE.Busy = False And IE.readyState = READYSTATE_COMPLETE                    
                    Exit For
                End If
            Next
        End If
    Next i
    IE.Quit

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2016-1-12 16:05 ½s¿è

¦^´_ 5# Hunt01
by xmlhttp
  1. Sub Test()
  2.     Dim oXmlhttp As Object: Set oXmlhttp = CreateObject("msxml2.xmlhttp")
  3.     Dim oRegexp As Object: Set oRegexp = CreateObject("vbscript.regexp")
  4.     Dim oHtmldoc As Object: Set oHtmldoc = CreateObject("htmlfile")
  5.     Dim oClip As Object: Set oClip = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}") 'or DataObject
  6.    
  7.     With oXmlhttp
  8.         .Open "GET", "http://mops.twse.com.tw/mops/web/t05sr01_1", False
  9.         .Send
  10.         oHtmldoc.write .responseText
  11.     End With
  12.    
  13.     Dim oTable As Object, oRow As Object, sParse As String, sPost As String
  14.     Set oTable = oHtmldoc.getelementbyid("table01").getelementsbytagname("form")(1).getelementsbytagname("table")(0)
  15.    
  16.     sParse = oTable.Rows(1).Cells(5).innerhtml '¥u¨ú²Ä¤@¦æ¸Ô²Ó¸ê®Æ
  17.     With oRegexp
  18.         .Pattern = ".*?SEQ_NO\.value='(.*?)'" & _
  19.                    ".*?SPOKE_TIME\.value='(.*?)'" & _
  20.                    ".*?SPOKE_DATE\.value='(.*?)'" & _
  21.                    ".*?COMPANY_ID\.value='(.*?)'" & _
  22.                    ".*?skey\.value='(.*?)'.*"
  23.         sPost = .Replace(sParse, "encodeURIComponent=1&TYPEK=all&step=1&skey=$5&COMPANY_ID=$4&SPOKE_DATE=$3&SPOKE_TIME=$2&SEQ_NO=$1")
  24.     End With
  25.    
  26.     With oXmlhttp
  27.         .Open "POST", "http://mops.twse.com.tw/mops/web/ajax_t05sr01_1", False
  28.         .SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  29.         .SetRequestHeader "Content-Length", Len(sPost)
  30.         .Send (sPost)
  31.         oHtmldoc.Close    'Set oHtmldoc = CreateObject("htmlfile")
  32.         oHtmldoc.write .responseText
  33.     End With
  34.     With oClip
  35.         .SetText oHtmldoc.body.innerhtml
  36.         .PutInClipboard
  37.     End With
  38.     Sheets.Add().PasteSpecial NoHTMLFormatting:=True
  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

stillfish00 ¤j¤j:

    §A¤Ó±j¤j¤F¡A¥Ñ°J·PÁ§A¼·¤¾´£¨Ñ¦¹½d¨Ò code!
    ¤p§Ì¥Ø«e¤w·|¨Ï¥Î click ¤è¦¡¨Ó¹F¦¨¡A¥u¬O¦³®É¤£ª¾¬°¦ó click ·|¥¢±Ñ¡A¥Ø«e·Q¨ìªº¤èªk¬°§PÂ_­Yºô­¶ click ¥¢±Ñ(¨S§ó·s)¡A´N¤£°±¦a click, ª½¨ì§ó·s¬°¤î¡C
    ¤j¤j©Ò´£¨Ñ¤§ xmlhttp ½d¨Ò¤p§Ì·|¦Aªá®É¶¡¦n¦n¬ãŪ¡A®z®zªº§Ú¥i¯à¤S±oªá¦n´X¬P´Á®ø¤Æ¥¦¤F¡A«¢¡C
    ¦A¦¸·PÁ¤j¤j!!

TOP

        ÀR«ä¦Û¦b : ¦n¨Æ­n´£±o°_¡A¬O«D­n©ñ±o¤U¡A¦¨´N§O¤H§Y¬O¦¨´N¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD