-1
  1. tr---- 0495024988

  2. 1996 年 8 月 14 日

  3. 04/04/130/02514/AM96/

  4. 23.01.1996

  5. 0495024988

6. tr----(这里有我复制到我的excel表的文本)

在这里,我阅读了许多给出 javascript 代码但没有 vba 代码的帖子。请帮我解决这个问题。

4

1 回答 1

0

子 GoToWebSiteAndPlayAroundNew()

Dim appIE As Object ' InternetExplorer.Application Dim URL As String Dim i As Long, strText As String

将 doc 作为对象,hTable 作为对象,hBody 作为对象,hTR 作为对象,hTD 作为对象 将 tb 作为对象,bb 作为对象,tr 作为对象,td 作为对象

Dim y As Long, z As Long, wb As Excel.Workbook, ws As Excel.Worksheet

将 sws 调暗为 SHDocVw.ShellWindows 将 IE 调暗为对象

将 vIE 调暗为 SHDocVw.InternetExplorer

设置 wb = Excel.ActiveWorkbook 设置 ws = wb.ActiveSheet

设置 appIE = CreateObject("InternetExplorer.Application") URL = " http://dgft.delhi.nic.in:8100/dgft/IecPrint "

y = 1 'Excel 中的 A 列 z = 1 'Excel 中的第 1 行

使用 appIE .navigate URL .Visible = True

Do While .busy: DoEvents: Loop Do While .ReadyState <> 4: DoEvents: Loop

.document.getElementById("iec").Value = "0495024988"

.document.getElementById("name").Value = "AMB"

结束于

出错时继续下一步

使用 appIE.document

Set elems = .getElementsByTagName("input") For Each e In elems

If (e.getAttribute("value") = "Submit Query") Then e.Click Exit For End If

下一个

以 Set sws = New SHDocVw.ShellWindows For Each vIE In sws 'If Left(vIE.LocationURL, 4) = "http" Then 'avoid explorer windows/etc this way 'If MsgBox("IE Window found. The URL is: " & vbCrLf & vIE.LocationURL & vbCrLf & _ 'vbCrLf & "你想看 html 吗?", vbYesNo) = vbYes Then 'Show html in a msgbox ' MsgBox vIE.document.body.innerHTML ' 或者放到一个文件 'dim vFF as long 'vff=freefile 'open "C:\thehtml.txt" 输出为 #vff 'print #vff,vie.document.body.innerhtml 'close #vff ' End If 'End If

 Set doc = vIE.document
 Set hTable = doc.getElementsByTagName("table")


 For Each tb In hTable

    Set hBody = tb.getElementsByTagName("tbody")
    For Each bb In hBody

        Set hTR = bb.getElementsByTagName("tr")

        MsgBox hTR.Length
        For Each tr In hTR


             Set hTD = tr.getElementsByTagName("td")
             MsgBox hTD.Length
             y = 1 ' Resets back to column A
             For Each td In hTD

               ws.Cells(z, y).Value = td.innerText
               y = y + 1
             Next td
             DoEvents
             z = z + 1

        Next tr
        Exit For
    Next bb
Exit For

下一个

下一个

结束子

于 2016-05-27T16:35:41.460 回答