gpt4 book ai didi

vba - 使用 vba 从受密码保护的网站中抓取数据用户定义类型未定义

转载 作者:行者123 更新时间:2023-12-04 21:53:34 26 4
gpt4 key购买 nike

我想从受密码保护的网站(https://www.vesseltracker.com/fr/Ports/Home.html)导入数据,我有用户名和密码。

我在这个网站上试过这个由 Dick 制作的 VBA 代码:http://dailydoseofexcel.com/archives/2006/11/29/html-tables/但它不起作用并且每次我调整它时都会卡住。

它卡在这里:Compile error:  User-defined type not defined

Sub GetTable()

Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Dim clip As DataObject

'create a new instance of ie
Set ieApp = New InternetExplorer

'you don’t need this, but it’s good for debugging
ieApp.Visible = True

'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "https://www.vesseltracker.com/fr/Home.html"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

Set ieDoc = ieApp.Document

'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.UserName.Value = "username"
.Password.Value = "password"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

'now that we’re in, go to the page we want
ieApp.Navigate "https://www.vesseltracker.com/fr/Port/tangermed/Dashboard.html"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

'get the table based on the table’s id
Set ieDoc = ieApp.Document
Set ieTable = ieDoc.all.Item

'copy the tables html to the clipboard and paste to teh sheet
If Not ieTable Is Nothing Then
Set clip = New DataObject
clip.SetText "" & ieTable.outerHTML & ""
clip.PutInClipboard
Sheet1.Select
Sheet1.Range("A1").Select
Sheet1.PasteSpecial "Unicode Text"
End If

'close 'er up
ieApp.Quit
Set ieApp = Nothing

End Sub

我真的很感谢你的帮助。谢谢你。

最佳答案

类型DataObject未定义,因为您的引用文献中不存在 MSForms。

您可以改用后期绑定(bind)在剪贴板中设置一些文本:

With VBA.CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText "1234"
.PutInClipboard
End With

关于vba - 使用 vba 从受密码保护的网站中抓取数据用户定义类型未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49510711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com