- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我承认我对 HTML 对象库不太有经验。
我有一个包含 IRS 雇主识别号的电子表格,我必须确定该电子表格是否在我的数据库中。我只能通过网络访问该数据库,其他人已经向该数据库编写了 HTML 并管理该数据库。我认为他们的方法已经过时,设计实践也很差劲;但我最终并不是一名数据库管理员,那么我知道什么呢?因此,我的正常做法是在搜索页面上输入 EIN 并记下结果。
我的 Excel 宏的目的是
登录基于网络的数据库查询站点。
循环访问 EIN,记录找到的 EIN
但是,我有以下问题:
我的代码如下(尽管我必须更改 URL):
Option Explicit
Sub FillFromWorkbookTest()
On Error GoTo ErrHandler
Const cURL = "https://www.someURL.com/LoginPage.jsp"
Const cUsername = "myUSERNAME"
Const cPassword = "myPASSWORD"
Dim IE As Object
Dim Doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UsernameInput As HTMLInputElement
Dim PasswordInput As HTMLInputElement
Dim LoginButton As HTMLInputButtonElement
Dim SearchForm As HTMLFormElement
Dim EINInput As HTMLInputElement
Dim SearchButton As HTMLInputButtonElement
Dim cEIN As String
Dim BotRow As Long
Dim EINRange As Range
Dim c As Variant
Dim i As Integer
Dim EINCheck As String
Dim EINCount As Integer
'## Open Browser & go to Admin Module, and Login
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate cURL
'## Wait for Adimn Module to load
Do Until IE.ReadyState = 4
DoEvents
Loop
'## Get the HTML Document of Admin Module login page (cURL)
Set Doc = IE.document
'## Get Admin Module login form
Set LoginForm = Doc.forms("f1")
'## Get Username input field and populate it
'## HTML: <input id=EIN type=text tabindex=3 size=9 maxlength=9 name=EIN title="Admin Code">
Set UsernameInput = LoginForm.elements("EIN")
UsernameInput.Value = cUsername
'## Get Password input field and populate it
'## HTML: <input id=PIN type=password tabindex=4 size=8 maxlength=8 name=PIN title="PIN">
Set PasswordInput = LoginForm.elements("PIN")
PasswordInput.Value = cPassword
'## Submit LoginForm
'## HTML: <input type=submit value=Login tabindex=5 title="Login"> (no onClick attribute; no element)
LoginForm.submit
Do Until IE.ReadyState = 4
DoEvents
Loop
'## Get the HTML Document of the new page
Set Doc = IE.document
'## Determine if login succeeded
If InStr(Doc.body.innerText, "Invalid Login.") = 0 Then
MsgBox "Login successful."
Else
MsgBox "Login failed."
End If
Debug.Print "Current URL: " & IE.LocationURL
'## Navigate to Global Change and reset HTML Document
IE.Navigate "https://www.someURL.com/LOGGED_IN/SomePage.jsp"
Do Until IE.ReadyState = 4
DoEvents
Loop
Set Doc = IE.document
'## Find last row in spreadsheet
BotRow = Worksheets("Sheet1").Range("A1").End(xlDown).Row
Set EINRange = Range("A1:A" & BotRow)
'## Set loop counter variable
i = 0
'## Cycle through IRS-identified EINs
For Each c In EINRange.Cells
cEIN = c.Value
i = i + 1
'## Get Admin Module login form
Set SearchForm = Doc.forms(0)
'## Get EIN input field and populate it
'## HTML: <input type="text" id=EIN name=EIN title="Enter charity EIN" maxlength=9 size=9 tabindex=11 >
Set EINInput = SearchForm.elements("EIN")
EINInput.Value = cEIN
'## Submit SearchForm
'## HTML: <input type="submit" value="Search" tabindex=15 title="Click here to search charity application" class="black_bold"
'## onclick="if (btn_OnClick(EIN,CODE)) {document.f1.action='SomeOther.jsp'; document.f1.submit(); return true;} else return false;" >
'## (has onClick attribute)
Set SearchButton = Doc.body.getElementsByTagName("table")(2). _
getElementsByTagName("tr")(0). _
getElementsByTagName("td")(0). _
getElementsByTagName("input")(2)
SearchButton.Click
Do Until IE.ReadyState = 4
DoEvents
Loop
'## Get the HTML Document of the new page
Set Doc = IE.document
'## Find EIN string on resulting page; Some number if found; Null if not
EINCheck = Doc.body.getElementsByTagName("table")(3).innerText
EINCount = InStr(1, EINCheck, cEIN, 1)
MsgBox EINCount
'## Determine which EINs are CFC charities
If InStr(1, EINCheck, cEIN, 1) = 0 Then
Worksheets("Sheet1").Range("F" & i).Value = "NO"
Else
Worksheets("Sheet1").Range("F" & i).Value = "YES"
End If
Next c
ErrHandler:
'## Cleanup
MsgBox "Error" & Err.Number & ": " & Err.Description
Set IE = Nothing
Set Doc = Nothing
Set LoginForm = Nothing
Set UsernameInput = Nothing
Set PasswordInput = Nothing
Set LoginButton = Nothing
Set SearchForm = Nothing
Set EINInput = Nothing
Set SearchButton = Nothing
End Sub
有什么建议吗?
最佳答案
我发现使用以下“等待 IE 准备就绪”可以取得更好的成功
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Function IEWait(p_ieExp As InternetExplorer)
'this should go from ready-busy-ready
Dim initialReadyState As Integer
initialReadyState = p_ieExp.ReadyState
'wait 250 ms until it's done
Do While p_ieExp.Busy Or p_ieExp.ReadyState <> READYSTATE_COMPLETE
Sleep 250
Loop
End Function
你会这样调用它
IEWait IE 'your internet explorer is named "IE"
仅使用“就绪”条件之一时,我遇到了太多奇怪的错误。将我的“就绪”检查修改为该方法后,这种情况几乎 100% 消失了。有时就绪状态并不能准确反射(reflect)状态。
关于您的第一个问题,使用我上面引用的 Sleep
方法,尝试在每个命令之前添加 Sleep 1000
左右,以验证问题是否存在于您的逻辑中,并且在 IE 中加载速度不会太慢。或者使用调试器慢慢地单步调试。
您所描述的内容听起来与我在 IE 部分加载并且我的代码将继续执行时遇到的一些问题非常相似。
关于VBA:循环中与 IE.doc 引用不一致的错误 91,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21335370/
我编写了一个 c# 程序,并在未安装 MS-Office 的 PC 中将其与文件扩展名(如 DOC)相关联。然后,我双击名称中包含空白字符的任何文件,我的程序将启动以打开该文件。我使用了以下语句: s
我试过创建、批量更新、从 https://developers.google.com/docs/api/how-tos/overview 获取. 即使在 batchUpdate 中,我也看不到编辑 t
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在尝试使用新 API 更新 Google 文档中的表格。表格链接自 Google 表格。 我尝试了谷歌云中的 API 资源管理器。我能够以 json 格式提取文档,然后过滤出表格。但是在表 jso
将 Google Docs Java API 与 Google Apps 帐户一起使用,是否可以模拟用户并下载文件? 当我运行下面的程序时,它显然是登录到域并冒充用户,因为它检索其中一个文件的详细信息
我试图通过 apidoc 生成 API 文档 如果我的回应是一个数组 [ {"id" : 1, "name" : "John"}, {"id" : 2, "name" : "Mary"}
是否可以在没有身份验证的情况下在 Google Docs 中查询公开共享的用户文档? 我正在寻找的特定最终目标是能够提供用户 ID,然后列出所有公开共享的文档,并在集合中带有特定标记。 谢谢。 最佳答
我对Elasticsearch映射感到困惑 首先,我创建了一个带有映射请求的文档 PUT /person { "mappings":{ "properties":{ "firs
我有一个可在一个电子表格中运行的 Google 文档查询。但是,当我复制电子表格时,查询不起作用,并且收到解析错误:无法解析函数 QUERY 参数 2 的查询字符串:NO_COLUMNCol2。 我的
我有一个如下所示的 XML 文档: _1 _2 TASK _3 TASK 我必须使用第一个文档中的节点属性创建另一
我没有看到什么? RTD features页面说: PDF Generation When you build your project on RTD, we automatically build
我有一个网页,我在 iFrame 中嵌入了一个 Google 文档查看器 (其中 URL-encoded-URL 是实际编码的 URL)。 对于我的许多/大多数用户,Google PDF 文档查看器
我如何在我的项目中使用 GOOGLE DOCS,我正在使用 asp.net 和 C# 作为后面的代码。 基本上我需要在浏览器中以只读形式显示一些 pdf、doc、dox、excel 文档。 提前致谢
从看起来像的 Google Doc 开始: * Item 我希望进行一系列 API 调用以将文档转换为: * Item - Subitem 但是,我不知道如何使用 API 做到这一点。 Crea
我需要控制我网站中嵌入的 Google 文档查看器。更具体地说,我需要能够启用/禁用 Google 幻灯片 View 的控件,并能够使用 JavaScript 启动/停止演示文稿。 我无法为此找到任何
我想使用 Google Docs API 将页眉和页脚添加到现有的 Google 文档文件中. 看着documents.batchUpdate ( link ) 我们可以插入文本、替换文本、添加图像和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 4 年前。 Improve
我已按照 GitHub 的文档进行操作,并使用 docs 成功发布了我的项目页面。我的项目存储库下的文件夹。但我想知道如何解决这个小问题: 我正在开发一个 JavaScript 库 wesa.js ,
我的程序正在创建文档,每个文档都有需要放入其中的文本。任何调用 InsertTextRequest 的尝试调用错误。 List requests = new ArrayList<>(); reques
基于此: Set field to automatically insert time-stamp on UPDATE? 我正在尝试创建适合我需要的触发器,但我发现使用 OLD 和 NEW 关键字不方
我是一名优秀的程序员,十分优秀!