Jump to content

Possible to retrieve html into text file?


oemript
 Share

Recommended Posts

Please see following image for checking error, once loop is stopped, it identified "$odivlogNext.ClassName not Existed", but when I go to IE and inspect elements, $odivlogNext.ClassName is existed as shown on image.

 

Do you have any suggestions on what to check next?
Thanks, to everyone very much for any suggestions (^v^)

 

#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")
ConsoleWrite ( "Main 1" & @LF)

If @error Or $otradeLog = Null Then
   if @error then  ConsoleWrite ( "Error ")
   If $otradeLog = Null  Then ConsoleWrite ( "Main 1 charttype = NULL" & @LF)
Else
   ConsoleWrite ( "Main 1 charttype Existed" & @LF)
EndIf

_IEAction($otradeLog, "click")
ConsoleWrite ( "Main 2" & @LF)
Global $odivlogNext = _IEGetObjById($oIE, "divLogNext")
_IEAction($odivlogNext, "focus")

If @error Or $odivlogNext = Null Or (Not IsObj($odivlogNext)) Then
  if @error then  ConsoleWrite ( "Error ")
  If $odivlogNext = Null  Then ConsoleWrite ( "Main 3 divLogNext = NULL" & @LF)
  If (Not IsObj($odivlogNext))  Then ConsoleWrite ( "Main 3 divLogNext is not Obj" & @LF)

Else
   ConsoleWrite ( "Main 3 divLogNext Existed" & @LF)
EndIf

While $odivlogNext.ClassName = "float_r pad0imp rel jshoverwithclass sel"
   _Check_Global()
   If @error Or $odivlogNext.ClassName = Null Then
      if @error then  ConsoleWrite ( "Error ")
      If $odivlogNext.ClassName = Null  Then ConsoleWrite ( "Main 4 $odivlogNext.ClassName = NULL" & @LF)
   Else
      ConsoleWrite ( "Main 4 $odivlogNext.ClassName Existed" & @LF)
   EndIf

   ConsoleWrite ( "Main 4" & $odivlogNext.ClassName & @LF)
    _GetTradeLog()
    ConsoleWrite ( "Main 5" & @LF)
    _IEAction($odivlogNext, "click")
    ConsoleWrite ( "Main 6" & @LF)
    Sleep(2000)
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 _Check_Global()
   If @error Or $otradeLog = Null Or (Not IsObj($otradeLog)) Then
      if @error then  ConsoleWrite ( "Error ")
      If $otradeLog = Null  Then ConsoleWrite ( "Global charttype = NULL" & @LF)
      If (Not IsObj($otradeLog))  Then ConsoleWrite ( "Global charttype is not Obj" & @LF)
   Else
      ConsoleWrite ( "Global charttype Existed" & @LF)
   EndIf

   If @error Or $odivlogNext = Null Or (Not IsObj($odivlogNext)) Then
      if @error then  ConsoleWrite ( "Error ")
      If $odivlogNext = Null  Then ConsoleWrite ( "Global divLogNext = NULL" & @LF)
      If (Not IsObj($odivlogNext))  Then ConsoleWrite ( "Global divLogNext is not Obj" & @LF)
   Else
      ConsoleWrite ( "Global divLogNext Existed" & @LF)
   EndIf

   If @error Or $odivlogNext.ClassName = Null Then
      if @error then  ConsoleWrite ( "Error ")
      If $odivlogNext.ClassName = Null  Then ConsoleWrite ( "Global $odivlogNext.ClassName = NULL" & @LF)
   Else
      ConsoleWrite ( "Global $odivlogNext.ClassName Existed" & @LF)
   EndIf
EndFunc

Func _Check_Local()
   If @error Or $otradeLog1 = Null Or (Not IsObj($otradeLog1)) Then
      if @error then  ConsoleWrite ( "Error ")
      If $otradeLog1 = Null  Then ConsoleWrite ( "Local tradeLog1 = NULL" & @LF)
      If (Not IsObj($otradeLog1))  Then ConsoleWrite ( "Local tradeLog1 is not Obj" & @LF)
   Else
      ConsoleWrite ( "Local tradeLog1 Existed" & @LF)
   EndIf

   If @error Or $otradeLog2 = Null Or (Not IsObj($otradeLog2)) Then
      if @error then  ConsoleWrite ( "Error ")
      If $otradeLog2 = Null  Then ConsoleWrite ( "Local tradeLog2 = NULL" & @LF)
      If (Not IsObj($otradeLog2))  Then ConsoleWrite ( " tradeLog2 is not Obj" & @LF)
   Else
      ConsoleWrite ( "Local tradeLog2 Existed" & @LF)
   EndIf

EndFunc

Func _GetTradeLog()
    ConsoleWrite ( "GetTradeLog 0" & @LF)

    Global $atradeLog1, $btradeLog1 = True, $atradeLog2, $btradeLog2 = True
    _Check_Global()
   ConsoleWrite ( "GetTradeLog 1" & @LF)
    _Check_Global()
;~ Get left Trade Log table
    Global $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")
    ConsoleWrite ( "GetTradeLog 2" & @LF)
    _Check_Global()
    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
     ConsoleWrite ( "GetTradeLog 3" & @LF)
     _Check_Global()
;~ Get right Trade Log Table
    Global $otradeLog2 = _IEGetObjById($oIE, "tradeLog2")
    ConsoleWrite ( "GetTradeLog 4" & @LF)
    _Check_Global()
    _Check_Local()
    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

 

divLogNext.png

Edited by oemript
Link to comment
Share on other sites

My coding is just for checking purpose and update the latest coding as shown above.  Please see images as shown below

It seems that there is no problem on checking each variable, but get following error as shown below

"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1900) : ==> The requested action with this object has failed.:
If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject.document^ ERROR

Do you have any suggestions on what wrong error is about?
Thanks, to everyone very much for any suggestions (^v^)

 

 

 

Error5.png

Edited by oemript
Link to comment
Share on other sites

Would it be possible to add a loop to repeat until no error as shown below?

Would following code be correct coding for checking?

;~ Get left Trade Log table
    Do
      Sleep(1000)
      Global $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")
    Until (Not @error)

Error3.png

Furthermore, since the error looks strange, I don't know on whether if @error catch this kind of error.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Edited by oemript
Link to comment
Share on other sites

1) Testing in morning without any application running, I test a few times and get it done until the end of next button.

2) Testing in this afternoon with other application running (PC busy). Adding a loop do not help, which repeat 14 times and stop. 

I would like to know on what wrong it is to get error during PC busy, and how to handle it better?

Not IsObj($otradeLog1) - what do it mean?

Global $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")

Do
    Sleep(3000)
    Global $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")
      if @error then ConsoleWrite ( "@Error" & @LF)
      if $otradeLog1 = Null then ConsoleWrite ( "$otradeLog1 <> Null" & @LF)
      if Not IsObj($otradeLog1) then ConsoleWrite ( "Not IsObj($otradeLog1)" & @LF)
   Until (not @error) and $otradeLog1 <> Null and IsObj($otradeLog1)

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

 

Edited by oemript
Link to comment
Share on other sites

Referring to following image, @error = 7 and Not IsObj ($otradeLog1) are found error, but when I check html code, and find id="tradeLog1" available.

When I click Prev and Next button without any problem, I would like to know on what wrong is _IEGetObjById function.

Error12.png

Do
    Sleep(3000)
    Global $otradeLog1 = _IEGetObjById($oIE, "tradeLog1")
      $iError = @error
      if $iError then
         _IEAction($odivlogPrev, "click")
         Sleep(1000)
         _IEAction($odivlogNext, "click")
         ConsoleWrite ( "@Error = " & $iError & @LF)
      EndIf
      if $otradeLog1 = Null then
         _IEAction($odivlogPrev, "click")
         Sleep(1000)
         _IEAction($odivlogNext, "click")
         ConsoleWrite ( "$otradeLog1 = Null" & @LF)
      EndIf
      if Not IsObj($otradeLog1) then ConsoleWrite ( "Not IsObj($otradeLog1)" & @LF)

   Until (not @error) and $otradeLog1 <> Null and IsObj($otradeLog1)

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

 

 

Edited by oemript
Link to comment
Share on other sites

26 minutes ago, oemript said:

Does anyone have any suggestions?

Since you asked, I have a few --

  1. Try running the code as provided so that we can actually help you. Modifying it and then complaining that it doesn't work doesn't get you anywhere.
  2. Stick to one thread. It gets repetitive when you keep posting the same requests in multiple places
  3. Try something different. Perhaps there's an issue with your current workstation. Try running the script in another environment

Finally, here's a way to retrieve the data without having to page through it all --

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

_IEErrorNotify(True)

Global $oIE = _IECreate("http://www.aastocks.com/en/stocks/analysis/transaction.aspx?symbol=00005", 1)
Global $jsEval, $iLen, $iIndex, $sData

$oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0)
Do
    Sleep(250)
    $jsEval = Execute('$oIE.Document.head.eval')
Until IsObj($jsEval)

Do
    Sleep(250)
Until $jsEval("RawSummary.totalVol") <> 0

$sData = $jsEval("JSON.stringify(RawSummary.filterData)")

$sPattern = "(?:\""|\')(?:[^""]*)(?:\""|\')(?=:)(?:\:\s*)(?:\"")?(true|false|[-0-9]+[\.]*[\d]*(?=,)|[0-9a-zA-Z\(\)\@\:\,\/\!\+\-\.\$\ \\\']*)(?:\"")?"
$aData = StringRegExp($sData, $sPattern, $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay($aData)

 

Link to comment
Share on other sites

7 hours ago, Danp2 said:

Finally, here's a way to retrieve the data without having to page through it all --

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

_IEErrorNotify(True)

Global $oIE = _IECreate("http://www.aastocks.com/en/stocks/analysis/transaction.aspx?symbol=00005", 1)
Global $jsEval, $iLen, $iIndex, $sData

$oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0)
Do
    Sleep(250)
    $jsEval = Execute('$oIE.Document.head.eval')
Until IsObj($jsEval)

Do
    Sleep(250)
Until $jsEval("RawSummary.totalVol") <> 0

$sData = $jsEval("JSON.stringify(RawSummary.filterData)")

$sPattern = "(?:\""|\')(?:[^""]*)(?:\""|\')(?=:)(?:\:\s*)(?:\"")?(true|false|[-0-9]+[\.]*[\d]*(?=,)|[0-9a-zA-Z\(\)\@\:\,\/\!\+\-\.\$\ \\\']*)(?:\"")?"
$aData = StringRegExp($sData, $sPattern, $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay($aData)

 

It works, would it be possible to retrieve data in format as shown below?

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

Format.png

Edited by oemript
Link to comment
Share on other sites

Referring to following coding, I would like to know on how to convert the array to string and get a proper format into csv file, since there is only 2 columns.

Global $sTradeLog = '"' & _ArrayToString($sData, '","', -1, -1, '"' & @CRLF & '"') & '"'

;~ 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
Global $sTradeLog = '"' & _ArrayToString($sData, '","', -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)
FileClose($hFileOpen)

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

Format.png

Edited by oemript
Link to comment
Share on other sites

On following coding, $sData array cannot write into file, but "Start" can be written into file.

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

;~ 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, "Start" & @CRLF)
_FileWriteFromArray($hFileOpen, $sData, 1)
FileClose($hFileOpen)
ShellExecute($sFileOpen)

From another example, $sTradeLog array can write into file with proper csv format with 6 columns. I would like to know on how modify ArrayToString's parameter in order to fit 2 columns' data from $sData.

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

;~ 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
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)
FileClose($hFileOpen)
ShellExecute($sFileOpen)

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

Edited by oemript
Link to comment
Share on other sites

I have one suggestion for you which your mind seems to not recognize properly, but I swear that this is the last time I'm gonna tell you: do error checking/debug your code.

You keep asking for "suggestions", but you don't even put some effort to read the Help file and try to understand how some functions work.

From the Forum Etiquette:

- Lurk a little before you dive right in. Read a number of posts, or check out the group's archives.

I have no more suggestions for a person who doesn't even have the respect to listen to the suggestions ( and not the code ) of many.

And, I'd like to remind that:

Usually asking for a script is not taken too well, within reason. Keep in mind that this is a support forum, so please acknowledge that. We are here to help you with your scripts, not to spoon-feed code to you.

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I don't understand parameter's format

Given : Global $sTradeLog = '"' & _ArrayToString($sData, '","', -1, -1, '"' & @CRLF & '"') & '"'

Why not? : Global $sTradeLog = _ArrayToString($sData, ",", -1, -1, @CRLF)

Parameter 1 : $sData - array source

Parameter 2 : "," - using comma a $sDelim_Col

Parameter 3 : -1 - $iStart_Row, why is -1?

Parameter 4 : -1 $iEnd_Row, why is -1?

Parameter 5 : @CRLF  - $sDelim_Row, why use '"' & @CRLF & '"' (long words to represent @CRLF) ?

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

Link to comment
Share on other sites

1 hour ago, oemript said:

Why not? : Global $sTradeLog = _ArrayToString($sData, ",", -1, -1, @CRLF)

This should work. The difference is that the other method wraps each array element in quotes. You would see that if you bothered to test it. :'(

On your other questions, RTFM or view the underlying UDF code to understand how it works. :thumbsup:

Link to comment
Share on other sites

For 5 different stocks, I setup a loop, when I run for the first and second codes without any problem, but the third code receive following error as shown below.

For $j = 1 to 5

   Same coding here, I would like to know when code repeats for the next one, does it need any reset on previous setting before processing the next code to avoid any COM error?

Next

Referring to following image, I would like to know on what kind of error is that "Variable must be of type 'Object'." which loop forever.

Error13.png

 

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

Edited by oemript
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...