Hi!
I usually always find answers to my questions by searching this and other forums. Now that i have been struggling with a problem i cant figure out i am posting my first thread.
I been trying to learn to use VBA for scraping web pages. As the URL itself is a page used at work, i am not at liberty to share the link. I hope it is possible to understand the issue anyhow, it is probably very basic.
When page opens it is a log in page, after the login page there is search field that i wanna insert a number and scrape the result of this search.
Code so far:
My initial problem was that when i wanna put in value in the search field after i log in (After HtmlButtons(2).Click), nothing happened.
When i loop through elements in end of my code, it still prints elements from the first page despite the successful log in. Why is that?
I usually always find answers to my questions by searching this and other forums. Now that i have been struggling with a problem i cant figure out i am posting my first thread.
I been trying to learn to use VBA for scraping web pages. As the URL itself is a page used at work, i am not at liberty to share the link. I hope it is possible to understand the issue anyhow, it is probably very basic.
When page opens it is a log in page, after the login page there is search field that i wanna insert a number and scrape the result of this search.
Code so far:
Code:
Sub solid()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim UserN As MSHTML.IHTMLElement
Dim PassW As MSHTML.IHTMLElement
Dim SearchS As MSHTML.IHTMLElement
Dim HtmlButtons As MSHTML.IHTMLElementCollection
Dim htmlLinks As MSHTML.IHTMLElementCollection
Dim htmlButton As MSHTML.IHTMLElement
IE.Visible = True
IE.navigate "#"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
Set UserN = HTMLDoc.getElementById("j_username")
UserN.Value = "***"
Set PassW = HTMLDoc.getElementById("j_password")
PassW.Value = "**"
Set HtmlButtons = HTMLDoc.getElementsByTagName("input")
HtmlButtons(2).Click ' here i successfully log in to a new page.
Set htmlLinks = HTMLDoc.getElementsByTagName("a")
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
For Each htmlButton In htmlLinks
Debug.Print htmlButton.tagName, htmlButton.innerText
Next htmlButton
End Sub
My initial problem was that when i wanna put in value in the search field after i log in (After HtmlButtons(2).Click), nothing happened.
When i loop through elements in end of my code, it still prints elements from the first page despite the successful log in. Why is that?