RickB75 Posted April 18, 2014 Share Posted April 18, 2014 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 More sharing options...
Danp2 Posted April 18, 2014 Share Posted April 18, 2014 Have you considered using _IEDocReadHTML or _IEBodyReadHTML? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
RickB75 Posted April 18, 2014 Author Share Posted April 18, 2014 (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 April 18, 2014 by RickB75 Link to comment Share on other sites More sharing options...
Danp2 Posted April 18, 2014 Share Posted April 18, 2014 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
RickB75 Posted April 18, 2014 Author Share Posted April 18, 2014 (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 April 18, 2014 by RickB75 Link to comment Share on other sites More sharing options...
RickB75 Posted April 18, 2014 Author Share Posted April 18, 2014 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 More sharing options...
Danp2 Posted April 18, 2014 Share Posted April 18, 2014 What are you doing with the source once you have it saved in a file? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
RickB75 Posted April 18, 2014 Author Share Posted April 18, 2014 I use FileOpen and FileRead combined with multiple RegEx's to find data and to build arrays. Link to comment Share on other sites More sharing options...
Danp2 Posted April 18, 2014 Share Posted April 18, 2014 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
RickB75 Posted April 20, 2014 Author Share Posted April 20, 2014 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 More sharing options...
Palestinian Posted April 20, 2014 Share Posted April 20, 2014 How about sharing that website with us so we can see for ourselves? Link to comment Share on other sites More sharing options...
RickB75 Posted April 21, 2014 Author Share Posted April 21, 2014 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 More sharing options...
Exit Posted April 21, 2014 Share Posted April 21, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now