Sign in to follow this  
Followers 0
RickB75

How can I get text from IE's view source window?

13 posts in this topic

I'm running into a small problem with my script having errors and not fully running its course all the time. A little info about my script.

 I have to perform a right click on an IE  page and using Send keys to view the source of the page. I then save the source page as a txt file. Some times my pc loads the source page immediately  and sometimes it could take a few extra secs to load the source page in its own window. I'm  looking for a sure way to make sure the source page is fully loaded before the script returns. I know I could put a Sleep command in the script, but I would like something more reliable. What I've been trying to do is use

WinWaitActive("mywindow","</html>")

 and get the closing html tag but the script is not reading any of the text inside of IE's view source window.

My question is how would you guys read that window and look for the html closing tag from it??

 

Share this post


Link to post
Share on other sites



Have you considered using _IEDocReadHTML or _IEBodyReadHTML?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Let me give that a shot. Would you recommend just passing the window title in the parameter like this

_IEDocReadHTML("IE View Source Window Title")

Edited by RickB75

Share this post


Link to post
Share on other sites

No, that won't work. Take a look at the help file examples for _IECreate. You will use the resulting object in your call to _IEDocReadHTML.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Since the IE view source is in a different window, do you think I can still use the same Variable that I opened IE with using $oIE = _IECreate("my browsing session") ??

Edited by RickB75

Share this post


Link to post
Share on other sites

On the website that I'm getting the HTML from, I have to use send keys and view the source that way. If I use IEDocReadHTML or _IEBodyReadHTML, I get a completely different source file. The website consist of frames and I've checked that I'm getting the correct frame source but it is different from right clicking and getting the source that way.

Share this post


Link to post
Share on other sites

What are you doing with the source once you have it saved in a file?

Share this post


Link to post
Share on other sites

I use FileOpen and FileRead combined with multiple RegEx's  to find data and to build arrays.

Share this post


Link to post
Share on other sites

Ok. You should be able to accomplish the same thing using the IE functions. Since you said there are frames involved, you would need to use _IEFrameGetCollection or _IEFrameGetObjByName to obtain a reference to the desired frame. You could then use this with _IEBodyReadHTML to retrieve the desired text.

Share this post


Link to post
Share on other sites

Dan,

Thank you for your help but, using the methods your speaking of, the source of the webpage is returned after the client side mods. It's a different source then right click, view source. I've tried numerous methods to get the correct source for the webpage but they all returned the incorrect source or they failed. I've scoured the help file using the IE functions and Inet functions plus some of the functions from Trancexx's WinHTTP functions. I had more luck with the IE functions but they returned the source after the client side mods. I guess I'm just trying to figure out how to read the view source window that pops up. I can verify the title  but the function WinWaitActive doesn't see the closing html tag. I don't know if or how I can use IELoadWait because it loads in a different window.  

Share this post


Link to post
Share on other sites

How about sharing that website with us so we can see for ourselves?

Share this post


Link to post
Share on other sites

Here's a link to another post that I posted here about this particular problem.

Today, I'm trying to figure out how to read the view source window text in this post because I can't get the IE functions to work correctly. In a perfect world, I would love to  use IEReadHTML or a similar function to get the data that I need. So far, I haven't been able to get the correct data using a function that way. That's why I reverted to this option of active windows and Right Click > View Source on the Frame in.

Share this post


Link to post
Share on other sites

Perhaps this:

#include <inet.au3>
$URL = "http://www.autoitscript.com/forum/topic/160770-how-can-i-get-text-from-ies-view-source-window/#entry1167228"
$sSource = _INetGetSource($URL) ; test, if valid URL
If @error Then Exit MsgBox(16 + 262144, " ", "URL not found", 0)
$pid = ShellExecute("iexplore.exe", $URL, "", "", @SW_SHOW)
$hWinURL = (WinWait("[Class:IEFrame]", $URL, 15) ? (WinActivate("[LAST]") ? WinWaitActive("[LAST]") : 0) : SetError(1, 0, 0))
If @error Then Exit MsgBox(16 + 262144, " ", "URL not found", 0)
While 1
    ControlSend($hWinURL, "", "", "^u") ;  get source window
    $hWinSource = (WinWait("[Class:SOURCE_VIEWER]", "", 1) ? (WinActivate("[LAST]") ? WinWaitActive("[LAST]") : 0) : SetError(1, 0, 0))
    If Not @error Then ExitLoop
WEnd
While 1
    $sHTML = ControlGetText($hWinSource, "", "RICHEDIT50W1")
    If StringInStr($sHTML, "</html>") Then ExitLoop
    Sleep(50)
WEnd
MsgBox(64 + 262144, " ", StringLeft($sHTML, 300) & @LF & @LF & "******************* last 200 Bytes *******" & @LF & @LF & StringRight($sHTML, 200), 0)

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0