我需要获取网页上的具体数据,并将其放在Excel中
我需要一个程序最有可能macros访问当前打开的网页,然后抓住一个特定的数据,然后将其粘贴到Excel文件。
我不能在Excel中使用networking查询,因为我需要访问的网站是密码保护。
我大约将每天从100个网页复制粘贴到2000个网页的数据。
示例数据显示在我需要从网页获取的位置如下所示:
@Serial Code: 123345 ; @Database: DB001 ; @Title: Sample Tile
在Excel中应该是:| 12345 | DB001 | 样本标题
所以我需要的是1.转到网页2.运行macros获取数据3.转到下一个网页
我希望你可以帮助我
对于大多数强大的套件,您可以使用Web客户端的脚本语言,例如perl
或python
。 我用perl来完成。
对于密码问题,首先提交您的login信息并保存cookie ,使用cookie访问受密码保护的内容。
将页面内容保存为文本文件,parsing它以提取字段。
示例如何从vba读取html:Option Explicit
' Add References: ' - Microsoft HTML Object Library ' - Microsoft Internet Controls Private Const URL As String = "C:\temp\Test.html" Sub Test() Dim browser As InternetExplorer Set browser = New InternetExplorer With browser browser.Visible = True browser.Navigate URL Do: Loop Until browser.Busy = False End With Dim htmlDocument As htmlDocument Set htmlDocument = browser.Document ' input Dim inputElement As HTMLInputElement Set inputElement = htmlDocument.getElementById("input1") If (inputElement Is Nothing) Then Err.Raise 123456789, , "inputElement is nothing. ID not found." End If [a1] = inputElement.Value browser.Quit Set browser = Nothing End Sub
我不知道是否有任何准备好的macros来完成这项工作,但是你可以通过创build自定义应用程序来完成。
- 逐一获取网页查看源代码
- parsing页面视图源并使用string操作检索@Serial Code,@Database,@Title的值
- 使用一些插件将所有数据转储到Excel中。