由于“浏览器”中的 URL 链接而启动 javascript 函数
我使用 wininet 从一些主页获取源代码,然后分析它以获取一些信息。我在 Excel 中使用 VB 来做到这一点。 所有这些都工作正常,但现在我想从一个特殊页面获取信息。
我必须打开此页面并单击链接才能转到包含所需信息的一侧。 我的问题是,这个链接是一个 JavaScript 函数。所以我的问题是:是否可以通过 URL 打开一侧并启动 javascript 函数?
我使用以下 VB 函数:
'API-Deklarationen:
Private Declare Sub InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long)
Private Declare Function InternetOpenA Lib "wininet.dll" ( _
ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrlA Lib "wininet.dll" ( _
ByVal hOpen As Long, ByVal sUrl As String, _
ByVal sHeaders As String, ByVal lLength As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Sub InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As Long, ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long)
'Enumeration für Internet:
Public Enum InternetOpenType
IOTPreconfig = 0
IOTDirect = 1
IOTProxy = 3
End Enum
Public s As String
Public Function OpenURL( _
ByVal URL As String, _
Optional ByVal OpenType As InternetOpenType = IOTPreconfig _
) As String
Const INET_RELOAD = &H80000000
Dim hInet As Long
Dim hURL As Long
Dim Buffer As String * 2048
Dim Bytes As Long
'Inet-Connection öffnen:
hInet = InternetOpenA( _
"VB-Tec:INET", OpenType, _
vbNullString, vbNullString, 0)
hURL = InternetOpenUrlA( _
hInet, URL, vbNullString, 0, INET_RELOAD, 0)
'Daten sammeln:
Do
InternetReadFile hURL, Buffer, Len(Buffer), Bytes
If Bytes = 0 Then Exit Do
OpenURL = OpenURL & Left$(Buffer, Bytes)
Loop
'Inet-Connection schließen:
InternetCloseHandle hURL
InternetCloseHandle hInet
End Function
I'm using wininet to get the sourcecode from some homepages, afterwards I analyse that for some information. I use VB in Excel to do that.
All of this is working fine, but now I want to get information from a special page.
I have to open this page and click a link to go to the side with the wanted information.
My problem is, that this link is a javascript function. So my question: is it possible to open a side and start the javascript function due to a URL?
I use following VB Function:
'API-Deklarationen:
Private Declare Sub InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long)
Private Declare Function InternetOpenA Lib "wininet.dll" ( _
ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrlA Lib "wininet.dll" ( _
ByVal hOpen As Long, ByVal sUrl As String, _
ByVal sHeaders As String, ByVal lLength As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Sub InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As Long, ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long)
'Enumeration für Internet:
Public Enum InternetOpenType
IOTPreconfig = 0
IOTDirect = 1
IOTProxy = 3
End Enum
Public s As String
Public Function OpenURL( _
ByVal URL As String, _
Optional ByVal OpenType As InternetOpenType = IOTPreconfig _
) As String
Const INET_RELOAD = &H80000000
Dim hInet As Long
Dim hURL As Long
Dim Buffer As String * 2048
Dim Bytes As Long
'Inet-Connection öffnen:
hInet = InternetOpenA( _
"VB-Tec:INET", OpenType, _
vbNullString, vbNullString, 0)
hURL = InternetOpenUrlA( _
hInet, URL, vbNullString, 0, INET_RELOAD, 0)
'Daten sammeln:
Do
InternetReadFile hURL, Buffer, Len(Buffer), Bytes
If Bytes = 0 Then Exit Do
OpenURL = OpenURL & Left$(Buffer, Bytes)
Loop
'Inet-Connection schließen:
InternetCloseHandle hURL
InternetCloseHandle hInet
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该是可能的。尝试使用 InternetExplorer-Control,它提供了您需要的一切:
导航和脚本访问文档的能力。
InternetExplorer-Control
文档属性
It should be possible. Try to use the InternetExplorer-Control, it provides all you need:
ability to navigate and scripting-access to the document.
InternetExplorer-Control
Document-Property