Jump to content

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


Recommended Posts

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??

 

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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.  

Link to comment
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.

Link to comment
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)

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...