VBA – Experiencing a problem trying to get the html from a page after submitting data. via /r/learnprogramming


VBA – Experiencing a problem trying to get the html from a page after submitting data.

Already tried posting to the desolate /r/VBA and to stackoverflow

I need to do some html scraping for this VBA program. Trying to navigate to a page with a table of data and print it to the debugger. IE makes it to the new page, but my VBA debugger is printing a table from the first page. When other people run the same code, it's worked for them. They are getting the table from the results page. I'm totally at a loss as to where to look for this problem. Setting breakpoints and waiting don't seem to be the issue here, is there something wrong with my system or settings?

Sub Macro1() Dim ie Set ie = CreateObject("InternetExplorer.Application") Dim HTMLDoc As MSHTML.HTMLDocument Dim HTMLinputs As MSHTML.IHTMLElementCollection ie.Visible = True ie.navigate "http://ift.tt/2vpJuNI bin/prc6.cgi?&ms_user=monm&passwd=&srch_type=0&adv=0&out_type=0&district=1421" Do 'Until .readyState = 4 DoEvents Loop Until ie.readyState = 4 Application.Wait DateAdd("s", 2, Now) Set HTMLDoc = ie.document Dim CurrentElement As HTMLInputElement ' filling in the forms and submitting Dim els As IHTMLElementCollection Set els = HTMLDoc.getElementsByName("p_loc") Set CurrentElement = els(0) CurrentElement.Value = "11 michelle" Set HTMLinputs = HTMLDoc.getElementsByTagName("input") HTMLinputs(7).Click ' Waiting for new page to load... Do 'Until .readyState = 4 DoEvents Loop Until ie.readyState = 4 Application.Wait DateAdd("s", 2, Now) Set HTMLDoc = ie.document Debug.Print ie.document.URL ' Printing the contents of the table (should be the table on the results page) Dim tbl Set tbl = HTMLDoc.getElementsByTagName("table")(0) Dim tableText tableText = tbl.innerText Debug.Print tableText End Sub 

Let me know if I can provide any extra information, or if you can point me in the right direction. Thanks

Submitted July 15, 2017 at 09:15PM by Neut_CW
via reddit http://ift.tt/2tWkG1W

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s