tr ---- 0495024988
1996年8月14日
04/04/130/02514 / AM96 /
1996年1月23日
0495024988
6。 tr ----(这里的文字是我复制到excel表格的文本)
这里我已经阅读了许多帖子,其中给出了javascript代码,但vba代码不存在。请帮我解决这个问题。
答案 0 :(得分:0)
Sub GoToWebSiteAndPlayAroundNew()
Dim appIE As Object' InternetExplorer.Application Dim URL As String Dim i As Long,strText As String
Dim doc As Object,hTable As Object,hBody As Object,hTR As Object,hTD As Object Dim tb As Object,bb As Object,tr As Object,td As Object
Dim y As Long,z As Long,wb As Excel.Workbook,ws As Excel.Worksheet
Dim sws As SHDocVw.ShellWindows 将IE作为对象变暗
Dim vIE As SHDocVw.InternetExplorer
设置wb = Excel.ActiveWorkbook 设置ws = wb.ActiveSheet
设置appIE = CreateObject(" InternetExplorer.Application") 网址=" http://dgft.delhi.nic.in:8100/dgft/IecPrint"
y = 1' Excel中的A列 z = 1' Excel中的第1行
用appIE .navigate网址 .Visible = True
Do While .busy:DoEvents:Loop Do While .ReadyState<> 4:DoEvents:循环
.document.getElementById(" iec")。Value =" 0495024988"
.document.getElementById(" name")。Value =" AMB"
结束
On Error Resume Next
使用appIE.document
设置elems = .getElementsByTagName("输入") 对于每个电子元素
if(e.getAttribute(" value")="提交查询")然后 e.Click 退出 结束如果
下一个e
结束 设置sws = New SHDocVw.ShellWindows 对于每个vIE In sws '如果离开(vIE.LocationURL,4)=" http"然后以这种方式避免使用资源管理器窗口/等 '如果MsgBox(" IE窗口找到。该URL为:"& vbCrLf& vIE.LocationURL& vbCrLf& _ ' vbCrLf& "你想看到HTML吗?",vbYesNo)= vbYes然后 '在msgbox中显示html ' MsgBox vIE.document.body.innerHTML '或者将其放入文件中 ' dim vFF ' VFF = freefile '打开" C:\ thehtml.txt"输出为#vff ' print#vff,vie.document.body.innerhtml '关闭#vff '万一 '结束如果
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
下一个tb
下一步
End Sub