tecnomancer Posted February 4, 2018 Share Posted February 4, 2018 Hi New to autoit and I'm trying to automate some stuff for my thesis Need a little help. I have msg box with webpage response time When I'm trying to write this values to file I have just empty file This is part of longer code but this other parts are working fine ; Display Information for all Links #include <IE.au3> #include <File.au3> #include <Array.au3> #include <String.au3> #include <FileConstants.au3> $oIE = _IECreate("https://www.google.ie/search?q=google.ie+hurricane+irma") $sText = _IEBodyReadText ($oIE) $data1 = _StringBetween($sText, 'About ', ')') $ss1 = StringSplit($sText, 'Search Results',1) $ss2 = StringSplit($ss1[2],@CRLF,1) $data2 = StringReplace(StringReplace($ss2[1],' ...',@CRLF),'...Cached','')&@CRLF&$ss2[3] MsgBox(0, "", $data1[0]&')',$data2) ; Open the file for writing (append to the end of a file) and store the handle to a variable. Local $hFileOpen = FileOpen("C:test.txt", $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf ; Write data to the file using the handle returned by FileOpen. FileWrite($hFileOpen, "Line 2") FileWrite($hFileOpen, "This is still line 2 as a new line wasn't appended to the last FileWrite call." & @CRLF) FileWrite($hFileOpen, "someone " & $data1 & "" & @CRLF) FileWrite($hFileOpen, "Line 4") ; Close the handle returned by FileOpen. FileClose($hFileOpen) Link to comment Share on other sites More sharing options...
Subz Posted February 4, 2018 Share Posted February 4, 2018 You may require #RequireAdmin at the top of your script to write to C:\ for example another way to write Google Search results: #RequireAdmin #include <IE.au3> $oIE = _IECreate("https://www.google.ie/search?q=google.ie+hurricane+irma") $oIEId = _IEGetObjById($oIE, "rso") $oDivId = _IETagNameGetCollection($oIEId, "div") Local $hFileOpen = FileOpen("C:\Test.txt", 1) If $hFileOpen = -1 Then Exit MsgBox(16, "Error", "An error occurred whilst writing the temporary file.") For $oDiv in $oDivId If $oDiv.ClassName = "g" Then FileWrite($hFileOpen, StringReplace(StringReplace(StringReplace(_IEPropertyGet($oDiv, "innertext"), @CRLF & @CRLF & @CRLF, @CRLF), @CRLF & @CRLF, @CRLF), "cached" & @CRLF, "") & @CRLF) EndIf Next FileClose($hFileOpen) Link to comment Share on other sites More sharing options...
tecnomancer Posted February 4, 2018 Author Share Posted February 4, 2018 @Subz Thank you but not exactly I'm looking for I do not understand why variable $data1 and $data2 have value when displayed on msg box, but do not have any value when I'm trying to save them to file Link to comment Share on other sites More sharing options...
Subz Posted February 4, 2018 Share Posted February 4, 2018 a. You used $data1[0] in the MsgBox and then $data1 in FileWrite b. You used $data2 in your MsgBox, but $data2 returns a blank string, it also wasn't included in FileWrite tecnomancer 1 Link to comment Share on other sites More sharing options...
tecnomancer Posted February 4, 2018 Author Share Posted February 4, 2018 44 minutes ago, Subz said: a. You used $data1[0] in the MsgBox and then $data1 in FileWrite b. You used $data2 in your MsgBox, but $data2 returns a blank string, it also wasn't included in FileWrite Thank you I have to learn a lot. Seems I will be busy till May 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