View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Get address from iFrame reference in page source

I'm can interpret your question too many ways.

1) Do you already have the string?

MyString = <iframe src="https://reports.e2rm.com/ReportServer?/e2RM/Reports/
CustomKFCDonation&rs:Command=Render&SessionID=**SE SSIONIDHERE**&rc:parameters=false&RequestGUID=**GU IDHERE**&rc:toolbar=true"

then you just need to remove the charaters before the equal sign and send a
web request like this

Request = mid(MyString,instr(MyString,"=")+1
'Note if the string contains the double quotes they also have to be removed
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

'get web page
IE.Navigate2 Request
Do While IE.readyState < 4
DoEvents
Loop

2) Or do you already have an Internet object and are try to find the tag
item "iframe". Tags start with <iframe and end with /iframe or / . The
tag name is not necesssary and the en d of the tag but is nicer to have to
make the code more readible.

set MyTag = IE.document.getelementsbytagname("iframe")

this will get all the iframe items. You may have to look through each one
to find the correct one.

for each itm in Mytag
if itm.ClassName = "xyz" then

end if

next itm



3) Another trick is search for id="abc" on the internet object

Set PageNumber = IE.document.getElementById("abc")



4) When all fails

RowCount = 1
for each itm in IE.Document.All
Range("A" & RowCount) = itm.classname
Range("B" & RowCount) = left(itm.innertext,256) 'this is very long an
can cause memory errors
Range("C" & RowCount) = itm.tagname

RowCount = RowCount + 1
next itm




" wrote:

On Sep 11, 6:38 pm, wrote:
On Sep 11, 3:57 pm, Joel wrote:



See if this helps


First example I boke you long string into several lines by using the & and
continuation character (_)


Sub Report()


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


URL = "https://reports.e2rm.com/ReportServer"
Request = "?/e2RM/Reports/CustomKFCDonation&" & _
"rs:Command=Render&" & _
"SessionID=**SESSIONIDHERE**&" & _
"rc:parameters=false&" & _
"RequestGUID=**GUIDHERE**&" & _
"rc:toolbar=true"


'get web page
IE.Navigate2 URL & Request
Do While IE.readyState < 4
DoEvents
Loop


end sub
--------------------------------------------------------------------------- ------------
Now I broke the command up to serveral variables


Sub Report()


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


CommandString = "rs:Command=Render&"
SessionString = "SessionID=**SESSIONIDHERE**&"
ParameterString = "rc:parameters=false&"
GuideString = "RequestGUID=**GUIDHERE**&"
ToolbarString = "rc:toolbar=true"


URL = "https://reports.e2rm.com/ReportServer"
Request = "?/e2RM/Reports/CustomKFCDonation&" & _
CommandString & _
SessionString & _
ParameterString & _
GuideString & _
ToolbarString


'get web page
IE.Navigate2 URL & Request
Do While IE.readyState < 4
DoEvents
Loop


end sub
--------------------------------------------------------------------------- ------------
Finally I made the SessionID a varialbe


Sub Report()


Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


SessionID = "**SESSIONIDHERE**"


CommandString = "rs:Command=Render&"
SessionString = "SessionID=" & SessionID & "&"
ParameterString = "rc:parameters=false&"
GuideString = "RequestGUID=**GUIDHERE**&"
ToolbarString = "rc:toolbar=true"


URL = "https://reports.e2rm.com/ReportServer"
Request = "?/e2RM/Reports/CustomKFCDonation&" & _
CommandString & _
SessionString & _
ParameterString & _
GuideString & _
ToolbarString


'get web page
IE.Navigate2 URL & Request
Do While IE.readyState < 4
DoEvents
Loop


end sub


" wrote:
Hello!


I know this is not directly related to Excel programming, but I am
building a macro to download a report from our online tool into Excel..


The web address string is always the same except for the session ID
and the RequestGUID, but the address is the only place that I see it
referenced. Is there any way to extract that from the following
address into a macro variable?


<iframe src="https://reports.e2rm.com/ReportServer?/e2RM/Reports/
CustomKFCDonation&rs:Command=Render&SessionID=**SE SSIONIDHERE**&rc:paramete rs=false&RequestGUID=**GUIDHERE**&rc:toolbar=true"


Thanks for your help!


Steven


Hi Joel:

The code looks good for rendering it, my biggest challenge though is
extracting the SessionID and RequestGUID from the page source. It
appears in a segment "<iframe src=", followed by the url you
dissected. Do you know how to call on the page source and look for
that?

Actually, if that can be extracted, then the entire URL could be,
which would probably be more effective.

Nearly there.

Steven


Wow, I don't think I could have been more unclear than these couple of
posts.

Let's try this again.

1. I have created a macro that navigates through an series of online
forms that lead to a report I need to download

2. The generated report is contained in an iFrame and I cannot figure
out how to send commands to the objects or fields within the iFrame

3. When I extract (manually) the iFrame page address from the page
source and navigate to it, I can send commands to the page.

I'm not sure what the best approach to this is, but I am imagining
that I call on the page source with code, search for the "<iframe
src="and extract the address from there.

My question - how do I access the page source using code to get that
address? Here's the example


<iframe src="https://reports.e2rm.com/ReportServer?/e2RM/Reports/
CustomKFCDonation&rs:Command=Render&SessionID=**SE SSIONIDHERE**&rc:parameters=false&RequestGUID=**GU IDHERE**&rc:toolbar=true"


Steven