由于“浏览器”中的 URL 链接而启动 javascript 函数

发布于 2024-09-26 17:15:24 字数 1883 浏览 5 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小鸟爱天空丶 2024-10-03 17:15:24

这应该是可能的。尝试使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文