PDA

View Full Version : Web scraping with complex chronological events



Frederic
09-01-2017, 07:17 AM
Hello,

My apologies if this code below looks messy, I'm still in the process of learning VBA, nonetheless with the help of google and many info over the web I was able to put this code together, but I'm still missing the logic behind it. So please understand that at the moment it looks like a piece of Swiss cheese...

The structure of the code would allow a user to fill an inputBox for each question or a fill a Userform.

The inputbox/userform would then look up /plug in the details over the following website : eqrreportviewer.ferc.gov

i.e.

- Open download tab : id="__tab_TabContainerReportViewer_TabPanelDownloads" class="ajax__tab_tab"

- fill Company : i.e. storage
- select year : i.e. 2017
- select quarter : i.e. Q1

then submit "search" : name="TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$btnSearch"

then click "Select all" : name="TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$btnSelectAll"

then fill a random "email address" : xy"at"xyz.com : name="TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$txtEmail"

and finally "submit" : name="TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$btnDownload"

and finally "download" of the FTP server which I still need to give a double check.


Anyone ?


Thank you for you help in advance,



Sub FillInternetForm()
Dim ie As Object
Dim html As HTMLdocument
Dim form As Variant, button As Variant
Dim HTMLdoc As HTMLdocument
Dim li As HTMLLIElement



Set ie = CreateObject("internetExplorer.Application")

mycompanyname = InputBox("Enter the name of the seller Company i.e. Wind Energy")
myyear = InputBox("Enter the year of the data you are looking for i.e. 2017")
myquarter = InputBox("Enter the Quarter your are looking for i.e. Q1")

With ie

.Visible = True
.navigate ("https://eqrreportviewer.ferc.gov/")

' Until page is loaded

Do While ie.ReadyState <> READYSTATE_COMPLETE

Application.StatusBar = "loading Web Page ..."

DoEvents

Loop

Set html = ie.document

Dim drp As HTMLFormElement
Set Drip = html.getElementById("ajax__tab_tab")
Dim x As Long
x = html.forms.Length
MsgBox x

For x = 0 To 3
Cells(x + 1, 1) = drp.Item(x).innerText
Next x

drp.selectedindex = 0

Set ie = Nothing
Application.StatusBar = ""


Wend

ie.document.getElementsById("TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$txtFilingOrg").Item.inertext = mycompanyname
ie.document.getElementsById("TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$ddlYear").Item(0).Value = myyear
ie.document.getElementsById("TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$ddlQuarter").Item.innerText = myquarter

With ie.document

Set form = ie.document.getelementsbyTagname("input")
For Each e In elms

If (e.getattribute("value") = ("TabContainerReportViewer$TabPanelDownloads$TabContainerDownloads$TabPanelSe lectiveFilings$btnSearch")) Then
e.Click



Set button = form(0).onsubmit
form(0).sumbit

End With



End Sub