ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capture values from a web page drop-down list (https://www.excelbanter.com/excel-programming/423368-capture-values-web-page-drop-down-list.html)

Paul Martin[_2_]

Capture values from a web page drop-down list
 
OK, I posted about this previously, seeking code not browser-
dependent. I've revised my plan and am now attempting to capture the
values in a web page drop-down list, via Internet Explorer. I have
identified the element that contains the drop-down and can capture its
current value, but I want to capture all the values in the list. Any
suggestions?

Thanks in advance

Paul Martin
Melbourne, Australia

Tim Williams[_2_]

Capture values from a web page drop-down list
 
Just loop through the options and check the .value or .text properties
(depending on which you need).

Dim o as object
for each o in objList.options
debug.print o.value & ":" & o.text
next o

where objList is your reference to the list.

Tim

"Paul Martin" wrote in message
...
OK, I posted about this previously, seeking code not browser-
dependent. I've revised my plan and am now attempting to capture the
values in a web page drop-down list, via Internet Explorer. I have
identified the element that contains the drop-down and can capture its
current value, but I want to capture all the values in the list. Any
suggestions?

Thanks in advance

Paul Martin
Melbourne, Australia




Paul Martin[_2_]

Capture values from a web page drop-down list
 
Thanks Tim

I've got it working, though I've refined it slightly by declaring my
variable as type MSHTML.HTMLOptionElement (which I ascertained by
debugging the object with typename.

Paul

Paul Martin[_2_]

Capture values from a web page drop-down list
 
I have my code working by firing up Internet Explorer, but it'd be
great to have a solution that simply used the html protocols to
interrogate a webpage drop-down, independent of browsers. Any other
suggestions?

Paul Martin[_2_]

Capture values from a web page drop-down list
 
This is what I have so far:

Dim HttpReq As New MSXML2.XMLHTTP
Dim HtmlDoc As New MSHTML.HTMLDocument

HttpReq.Open "GET", HTTP_PATH, False
HttpReq.send

Debug.Print HttpReq.Status

If HttpReq.Status = HTTPREQ_SUCCESS Then
HtmlDoc.body.innerHTML = HttpReq.responseText
End If

What I would like to know is if at this point in the code, HtmlDoc is
a variable representation of the webpage or whether it remains empty
until I 'navigate' to the URL.

I seem to be able to capture a form, as the following works:
Debug.Print HtmlDoc.forms("aspnetForm").Name

But the following fails (the item is the name of the drop-down list) &
I get Run-time error '91': Object variable or With block variable not
set:
Debug.Print HtmlDoc.forms("aspnetForm").Item
("ctl00$ContentPlaceHolder1$dpRecentReport").Na me

Any suggestions?


I have been unsuccessful in capturingdrop-down list from the web
page, eg, the following fails:

Debug.Print HtmlDoc.forms("aspnetForm").Name






Paul Martin[_2_]

Capture values from a web page drop-down list
 
Tim, your code finds the form but not the button
"ct100_ContentPlaceHolder1_imgAgree".
This fails: Debug.Print oForm.elements
("ct100_ContentPlaceHolder1_imgAgree").Name

Ron, I already have the IE solution working, but am trying to find a
browser-independent solution. And as you mention, the second
suggestion doesn't get past the "I Agree" button.

Thanks for the suggestions so far. I'm wracking my brain over this
one, so if anyone can get further on it, it'd be much appreciated.

Paul


Paul Martin[_2_]

Capture values from a web page drop-down list
 
I'm not sure what you mean, Tim, as there is no requirement to login,
just to click the "I Accept" button.

Paul

Tim Williams[_2_]

Capture values from a web page drop-down list
 
What I mean is that when I run your code in the VBE in XL I get an error
when the page loads within the MSHTML document object.
The error comes from javascript in the page: when I hit "debug" it takes me
to the MS script debugger which hilights the bit of javascript code I
posted.

Tim

"Paul Martin" wrote in message
...
I'm not sure what you mean, Tim, as there is no requirement to login,
just to click the "I Accept" button.

Paul




Paul Martin[_2_]

Capture values from a web page drop-down list
 
With VBA, I can navigate past the "I Agree" button, select a file from
the 'Recent Report' dropdown list and click the Save button. A File
Download dialog box then appears; can someone suggest how I can
programmatically click the Save button on this dialog box and save it
to the desktop?

Thanks in advance

Paul Martin
Melbourne, Australia


Tim Williams[_2_]

Capture values from a web page drop-down list
 
If it helps, each of those files in the drop-down is located in this
directory:

http://192.120.13.77/Data/Public/E_AUST/Archive/

So you may just be able to download it directly from there.

Tim


"Paul Martin" wrote in message
...
With VBA, I can navigate past the "I Agree" button, select a file from
the 'Recent Report' dropdown list and click the Save button. A File
Download dialog box then appears; can someone suggest how I can
programmatically click the Save button on this dialog box and save it
to the desktop?

Thanks in advance

Paul Martin
Melbourne, Australia




Paul Martin[_2_]

Capture values from a web page drop-down list
 
Tim, when you say "you may just be able to download it directly from
there", in what way specifically?

If I use IE, I get the 'File Download' dialog box. If I use the
URLDownloadToFile API, using that URL, it merely downloads the
Disclaimer page. I'm stuck on how to proceed. Any suggestions?

Paul


Tim Williams[_2_]

Capture values from a web page drop-down list
 
You could try using xmlhttp to grab the file using a GET request.
It might be necessary though to add the session cookies that get set in IE
when you go through the Disclaimer page. You can extract these from IE
using "document.cookie" and then add them as headers to your xmlhttp
request.

Downloading with xmlhttp (ASP example):
http://www.4guysfromrolla.com/webtech/110100-1.shtml

Adding cookies:
http://support.microsoft.com/default.aspx/kb/290899

Time to sleep now: I'll have a go at this myself tomorrow.

Tim



"Paul Martin" wrote in message
...
Tim, when you say "you may just be able to download it directly from
there", in what way specifically?

If I use IE, I get the 'File Download' dialog box. If I use the
URLDownloadToFile API, using that URL, it merely downloads the
Disclaimer page. I'm stuck on how to proceed. Any suggestions?

Paul




Paul Martin[_2_]

Capture values from a web page drop-down list
 

Thanks, Tim. I've tried the following code, but get stuck as per
comments in code. Any suggestions what I'm doing wrong?

Paul

================================================== =================
Private Const HTTP_PATH As String = "http://192.120.13.77/
viewtable.aspx?region=E_AUST&report=int924"
Private Const HTTPREQ_SUCCESS As Integer = 200
Private Const BUTTON_AGREE As String =
"ctl00_ContentPlaceHolder1_imgAgree"
Private Const DROPDOWN_RECENTREPORT As String =
"ctl00_ContentPlaceHolder1_dpRecentReport"

Sub GetHtmlPage()
Dim HttpReq As New MSXML2.XMLHTTP
Dim HtmlDoc As New MSHTML.HTMLDocument
Dim HtmlBtnAgree As MSHTML.HTMLButtonElement
Dim HtmlOpt As MSHTML.HTMLOptionElement

HttpReq.Open "GET", HTTP_PATH, False
HttpReq.send

If HttpReq.Status = HTTPREQ_SUCCESS Then
HtmlDoc.body.innerHTML = HttpReq.responseText
Set HtmlBtnAgree = HtmlDoc.all(BUTTON_AGREE)
Debug.Print TypeName(HtmlBtnAgree) ' Returns
HTMLInputElement, appears to work

HtmlBtnAgree.Value = True ' Emulate button click
Debug.Print HtmlDoc.body.innerHTML ' <<< STILL RETURNING
DISCLAIMER PAGE

For Each HtmlOpt In HtmlDoc.forms("aspnetForm").Item
(DROPDOWN_RECENTREPORT) ' << FAILS, page hasn't loaded
Debug.Print HtmlOpt.Text
Next HtmlOpt
End If
End Sub
'================================================= ==================


All times are GMT +1. The time now is 02:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com