Jump to content

Possible to retrieve html into text file?


oemript
 Share

Recommended Posts

34 minutes ago, oemript said:

Do you have any suggestions on how to append array into file using _FileWriteFromArray?

You are already doing it.

But, what does tell you if you have or not a valid array to write/append to your file?

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@oemript

Is so difficult to do what we're trying to suggest you from yesterday?

Add error checking to your code.

What are you expecting to write to your file? An array?

See if your functions return a valid array.

Do it your own.

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Within loop, when I only run Test1, it can run until the end of next button without any problem.

Within loop, when I only run Test2 without running other application, it stops in the middle of loop.

I would like to know on how to solve this strange behavior on repeat running following code.

Local $otradeLog1 = _IEGetObjById($oIE, "tradeLog1") Any debug tools on showing what error is about.

Does anyone have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

#include <Array.au3>
#include <IE.au3>
#include <File.au3>
Global $oGlobalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncGlobal") ; Global COM error handler
Global $bTradeLog = False, $aTradeLog
Global $oIE = _IECreate("http://www.aastocks.com/en/stocks/analysis/transaction.aspx?symbol=00005", 1)
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)
_IELoadWait($oIE, 5000)
Global $otradeLog = _IEGetObjByName($oIE, "charttype")
_IEAction($otradeLog, "click")
Global $odivlogNext = _IEGetObjById($oIE, "divLogNext")
While $odivlogNext.ClassName = "float_r pad0imp rel jshoverwithclass sel"

       _IEAction($otradeLog, "focus")
       _IEAction($odivlogNext, "focus")
       Sleep(200)
      ;_Test1() ; it works until the end of next button
      _Test2() ; it stops in the middle of loop
      _IEAction($odivlogNext, "focus")
       Sleep(200)
       _IEAction($odivlogNext, "click")
       Sleep(200)
WEnd

_IEQuit($oIE)

Func _Test1()
      Local $oLocalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncLocal") ; Local COM error handler
      Local $sFilePath = "D:\stocks.txt"
EndFunc

Func _Test2()
      Local $oLocalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncLocal") ; Local COM error handler
      Local $sFilePath = "D:\stocks.txt"
      Local $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")
EndFunc

 

Edited by oemript
Link to comment
Share on other sites

  • Moderators

@oemript Care to explain the thinking behind deleting post after post in this thread?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Can forum offer a delete option?  after testing and finding, the latest post would be the most appropriated for this issue.

Do you have any suggestions?

Thanks, to everyone very much for any suggestions (^v^)

Edited by oemript
Link to comment
Share on other sites

  • Moderators

Yes, the suggestion would have been to leave the context and simply edit. Or just leave it and state in your most recent post what finally worked, so someone encountering the same in the future would be able to see the steps you tried to get to the end result, rather than interrupting the flow of the thread with a bunch of blank posts - in other words, the suggestion would be to follow exactly what the forum rules state not to do in point 8.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

You can use something like this, this has been tested several times and writes the data into csv format D:\stocks.csv.

What I suggest is open IE navigate to the page first, check that the Full Transaction log includes data, when I run it now, there is no data, however if I select yesterdays info it populates.  Now run the script, if you get errors:

Check the source code of the page and make sure "charttype" id exists on the page, check "divLogNext" id exists on the page and lastly check that the divLogNext classname matches "float_r pad0imp rel jshoverwithclass sel".  As mentioned this runs fine for me and I get csv file which I can open in Excel without any issues.

Anyway don't have any further time for this, so will leave it with you.

#include <Array.au3>
#include <IE.au3>
#include <File.au3>

_IEErrorNotify(True)

Global $sStartTime = "Start Date/Time: " & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC
Global $bTradeLog = False, $aTradeLog
Global $oIE = _IECreate("http://www.aastocks.com/en/stocks/analysis/transaction.aspx?symbol=00005", 1)
;~ Global $hWnd = _IEPropertyGet($oIE, "hwnd")
;~  WinSetState($hWnd, "", @SW_MAXIMIZE)
;~  Sleep(5000)
Global $otradeLog = _IEGetObjByName($oIE, "charttype")
_IEAction($otradeLog, "click")
Global $odivlogNext = _IEGetObjById($oIE, "divLogNext")
While $odivlogNext.ClassName = "float_r pad0imp rel jshoverwithclass sel"
    _GetTradeLog()
    _IEAction($odivlogNext, "click")
    Sleep(100)
WEnd
;~ Get the last Transaction Log page.
_GetTradeLog()
_ArrayDisplay($aTradeLog)

;~ Write Data to file
Global $sFileOpen = "D:\Stocks.csv"
Global $hFileOpen = FileOpen($sFileOpen, 2) ;~ This will create a new file name overwriting content, use flag 1 if you wish to append data
FileWrite($hFileOpen, $sStartTime & @CRLF)
Global $sTradeLog = '"' & _ArrayToString($aTradeLog, '","', -1, -1, '"' & @CRLF & '"') & '"' ;~ To get a proper csv file, convert the array to string and then change "|" to '","' since Array data inludes commas
FileWrite($hFileOpen, $sTradeLog & @CRLF)
FileWrite($hFileOpen, "End Date/Time: " & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
FileClose($hFileOpen)
ShellExecute($sFileOpen)

Func _GetTradeLog()
    Local $atradeLog1, $btradeLog1 = True, $atradeLog2, $btradeLog2 = True
;~ Get left Trade Log table
    Local $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")
    If IsObj($otradeLog1) Then
        $atradeLog1 = _IETableWriteToArray($otradeLog1, True)
    Else
        ConsoleWrite("$otradeLog1 is not an object, check the source code to see if tradeLog1 exists." & @CRLF)
        $btradeLog1 = False
    EndIf
;~ Get right Trade Log Table
    Local $otradeLog2 = _IEGetObjById($oIE, "tradeLog2")
    If IsObj($otradeLog2) Then
        $atradeLog2 = _IETableWriteToArray($otradeLog2, True)
    Else
        ConsoleWrite("$otradeLog2 is not an object, check the source code to see if tradeLog2 exists." & @CRLF)
        $btradeLog2 = False
    EndIf
    If $bTradeLog = False Then
        If $btradeLog1 Then
            $aTradeLog = $atradeLog1
        ElseIf $btradeLog2 Then
            $aTradeLog = $atradeLog2
        EndIf
        If $btradeLog1 And $btradeLog2 Then
            _ArrayConcatenate($aTradeLog, $atradeLog2, 1)
            $bTradeLog = True
        ElseIf $btradeLog1 Then
            $bTradeLog = True
        ElseIf $btradeLog2 Then
            $bTradeLog = True
        EndIf
    Else
        If $btradeLog1 Then _ArrayConcatenate($aTradeLog, $atradeLog1, 1)
        If $btradeLog2 Then _ArrayConcatenate($aTradeLog, $atradeLog2, 1)
    EndIf
EndFunc

 

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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