Jump to content

How to grab data from website


Recommended Posts

Hello again folks,

can anyone help me to read data from this website:

--edited--

as picture shown (in a blue circle).. i just want to grab "SPOT" n write it with consolewrite.

How can i grab that "spot"? im confuse with that..

 

any support n help mean so much for me..Thank

 

Edited by Tripoz
Link to comment
Share on other sites

Any chance you could post what you have tried, so that we may help you with that?

We like to help, just not write complete code for others.

If you haven't tried anything, have a look at _IETagNameGetCollection and _IEPropertyGet using "innertext".

EDIT: I did inspect the element and it is a span tag with an ID of "spot".

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

you should wait a bit till the "spot" obj exists on the page. Then you can reference to it.
Try this variant to your script:

#include <IE.au3>
#include <Inet.au3>
#include <MsgBoxConstants.au3>

$oIE = _IECreate('https://www.binary.com/c/trade.cgi?market=random&time=5t&form_name=risefall&expiry_type=duration&amount_type=stake&H=S0P&currency=USD&underlying_symbol=R_50&amount=1&date_start=now&type=CALL&l=EN')
Local $Span

Do
    $Span = _IEGetObjById($oIE, "spot")
Until IsObj($Span) ; wait till the "spot" object exists on the page

;$oSpan = ObjGet($Span)
While 1
    ConsoleWrite($Span.InnerHTML & @CRLF)
    Sleep(1000)
WEnd

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

don't know the overall logic and the  purpose of your program, anyway maybe something like this could be a start

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

$Span = ConnectWebPage() ; get reference to "Span"
Local $RefreshRate = 1000 ; 1000 ms = refresh any 1 second
Local $Timer = TimerInit() ; Initialize timer

#region ### START Koda GUI section ### Form=C:\Users\Marcellino\Downloads\koda_1.7.3.0\Forms\project Pakdhe.kxf
$Form1 = GUICreate("Macro Martandang's Methode v.1", 349, 280, 192, 124)
$Group1 = GUICtrlCreateGroup(" Random Market ", 176, 48, 161, 49)
$Random = GUICtrlCreateCombo("R.100", 184, 64, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "R.25|R.50|R.75|R.Bear|R.Bull|R.Yang|R.Yin")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("  Method  ", 8, 8, 161, 137)
$Radio_Ujung = GUICtrlCreateRadio("Metode Ujung", 24, 56, 113, 17)
$Radio_Locking = GUICtrlCreateRadio("Metode Locking", 24, 32, 113, 17)
$Radio_Lambung = GUICtrlCreateRadio("Metode Lambung", 24, 80, 113, 17)
GUICtrlSetState($Radio_Lambung, $GUI_CHECKED)
$Radio_Cantik = GUICtrlCreateRadio("Metode Cantik", 24, 104, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("  Stake  ", 176, 96, 161, 49)
$Label1 = GUICtrlCreateLabel("Stake :", 184, 116, 38, 17)
$InputStake = GUICtrlCreateInput("5", 228, 112, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
$Label2 = GUICtrlCreateLabel("$", 311, 116, 10, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("  Martingale  ", 176, 8, 161, 41)
$Radio5 = GUICtrlCreateRadio("YES", 192, 24, 41, 17)
$Radio6 = GUICtrlCreateRadio("NO", 290, 24, 41, 17)
GUICtrlSetState($Radio6, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("  Barrier  ", 8, 152, 329, 49)
$Label3 = GUICtrlCreateLabel("High Barrier :", 16, 173, 65, 17)
$Label4 = GUICtrlCreateLabel("Low Barrier :", 190, 173, 63, 17)
$Input2 = GUICtrlCreateInput("-1.30000", 256, 168, 65, 21)
$Input1 = GUICtrlCreateInput("+1.30000", 82, 168, 73, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("  SPOT PRICE  ", 8, 202, 329, 39)
$Label4 = GUICtrlCreateLabel("SPOT  :", 96, 220, 65, 17)
$Label5 = GUICtrlCreateLabel("", 146, 220, 65, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&RUN", 8, 248, 99, 25)
$Button2 = GUICtrlCreateButton("STOP", 120, 248, 107, 25)
$Button3 = GUICtrlCreateButton("EXIT", 240, 248, 99, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$Timer = TimerInit()
While 1
    $idMsg = GUIGetMsg()
    Select
        Case $idMsg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $idMsg = $Button3
            ExitLoop
        Case $idMsg = $Radio_Ujung
            ;Radioujung()
            If GUICtrlRead($Radio_Ujung) = $GUI_CHECKED Then
                GUICtrlSetState($Input1, $GUI_DISABLE)
            EndIf
        Case $idMsg = $Radio_Cantik
            If GUICtrlRead($Radio_Cantik) = $GUI_CHECKED Then
                GUICtrlSetState($Input1, $GUI_ENABLE)
            EndIf

    EndSelect
    If TimerDiff($Timer) > $RefreshRate Then ; refresh only at refresh rate
        spot($Label5, $Span) ; Set Span value to $Label5
        $Timer = TimerInit() ; reset timer
    EndIf
WEnd

Func Radioujung()
    If GUICtrlRead($Radio_Ujung) = $GUI_CHECKED Then
        GUICtrlSetState($Input1, $GUI_DISABLE)
        GUICtrlSetState($Input2, $GUI_DISABLE)
    Else
        GUICtrlSetState($Input1, $GUI_ENABLE)
        GUICtrlSetState($Input2, $GUI_ENABLE)

    EndIf
EndFunc   ;==>Radioujung

Func Spot($hLabel, $Span)
    GUICtrlSetData($hLabel, $Span.InnerHTML)
EndFunc   ;==>Spot

Func ConnectWebPage()
    $oIE = _IECreate('https://www.binary.com/c/trade.cgi?market=random&time=5t&form_name=risefall&expiry_type=duration&amount_type=stake&H=S0P&currency=USD&underlying_symbol=R_50&amount=1&date_start=now&type=CALL&l=EN')
    Local $Span
    Do
        $Span = _IEGetObjById($oIE, "spot")
    Until IsObj($Span) ; wait till the "spot" object exists on the page
    Return $Span
EndFunc   ;==>ConnectWebPage

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

The site continuously reads out the value from a text-stream and display it on the site.

So it should be more efficient if you read out the stream directly.

A suggestion (you will need >>WinHTTP.au3<<):

#include <WinHTTP.au3>
Global Const $LineOffset = @ScriptLineNumber - 1

Global $hSession = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hSession, "www.binary.com", 443)
If @error Then _Error("Error in _WinHttpConnect", $hConnect)

$hRequest = _WinHttpSimpleSendSSLRequest($hConnect, 'GET', '/push/price/T_CALL_R-50_5t_S0P_c_USD_EN')
If @error Then _Error("Error in _WinHttpSimpleSendSSLRequest", $hRequest)

_WinHttpReceiveResponse($hRequest)

While 1
    If _WinHttpQueryDataAvailable($hRequest) Then
        $s_Response = _WinHttpReadData($hRequest, 0, @extended)
        If @error Then ExitLoop
        ConsoleWrite(StringRegExp($s_Response, 'spot":"(\d+\.\d+)', 1)[0] & @CRLF)
    EndIf
    If @error Then ExitLoop
    Sleep(100)
WEnd

_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hSession)


Func _Error(Const $s_Text, Const $Ret = Default, Const $b_Exit = True, Const $Error = @error, Const $Extended = @extended, Const $ScriptLine = @ScriptLineNumber)
    Local $s_Out = '"' & $s_Text & '"' & @CRLF & @CRLF & "Line: " & $ScriptLine - $LineOffset & @CRLF & "@error: " & $Error & @CRLF & "@extended: " & $Extended & ($Ret = Default ? "" : @CRLF & "Return value: " & $Ret)
    MsgBox(48, "Error", $s_Out)
    If $b_Exit Then Exit
EndFunc

 

Link to comment
Share on other sites

Thx alot @Chimp & @AspirinJunkie..

@Chimp
its get delay atleast 500-1000ms from web to program..can its faster??

@AspirinJunkie
could u help me to combine ur method with my GUI source bro??coz im nubie here n ur code is exactly what i want (without opening the IE page) but im so confused to combine urs n mine..:(

but its mean so much for me..thx alot

Link to comment
Share on other sites

You can do it this way:

#include <WinHTTP.au3>
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Global $hSession = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hSession, "www.binary.com", 443)
Global $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, 'GET', '/push/price/T_CALL_R-50_5t_S0P_c_USD_EN')
If @error Then Exit

_WinHttpReceiveResponse($hRequest)

#Region ### START Koda GUI section ### Form=C:\Users\Marcellino\Downloads\koda_1.7.3.0\Forms\project Pakdhe.kxf
$Form1 = GUICreate("Macro Martandang's Methode v.1", 349, 280, 192, 124)
$Group1 = GUICtrlCreateGroup(" Random Market ", 176, 48, 161, 49)
$Random = GUICtrlCreateCombo("R.100", 184, 64, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "R.25|R.50|R.75|R.Bear|R.Bull|R.Yang|R.Yin")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("  Method  ", 8, 8, 161, 137)
$Radio_Ujung = GUICtrlCreateRadio("Metode Ujung", 24, 56, 113, 17)
$Radio_Locking = GUICtrlCreateRadio("Metode Locking", 24, 32, 113, 17)
$Radio_Lambung = GUICtrlCreateRadio("Metode Lambung", 24, 80, 113, 17)
GUICtrlSetState($Radio_Lambung, $GUI_CHECKED)
$Radio_Cantik = GUICtrlCreateRadio("Metode Cantik", 24, 104, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("  Stake  ", 176, 96, 161, 49)
$Label1 = GUICtrlCreateLabel("Stake :", 184, 116, 38, 17)
$InputStake = GUICtrlCreateInput("5", 228, 112, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))
$Label2 = GUICtrlCreateLabel("$", 311, 116, 10, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("  Martingale  ", 176, 8, 161, 41)
$Radio5 = GUICtrlCreateRadio("YES", 192, 24, 41, 17)
$Radio6 = GUICtrlCreateRadio("NO", 290, 24, 41, 17)
GUICtrlSetState($Radio6, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("  Barrier  ", 8, 152, 329, 49)
$Label3 = GUICtrlCreateLabel("High Barrier :", 16, 173, 65, 17)
$Label4 = GUICtrlCreateLabel("Low Barrier :", 190, 173, 63, 17)
$Input2 = GUICtrlCreateInput("-1.30000", 256, 168, 65, 21)
$Input1 = GUICtrlCreateInput("+1.30000", 82, 168, 73, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("  SPOT PRICE  ", 8, 202, 329, 39)
$Label4 = GUICtrlCreateLabel("SPOT  :", 96, 220, 65, 17)
$Label5 = GUICtrlCreateLabel("", 146, 220, 65, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&RUN", 8, 248, 99, 25)
$Button2 = GUICtrlCreateButton("STOP", 120, 248, 107, 25)
$Button3 = GUICtrlCreateButton("EXIT", 240, 248, 99, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AdlibRegister(_SpotRefresh, 500)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button3
            End()
        Case $Radio_Ujung
            If GUICtrlRead($Radio_Ujung) = $GUI_CHECKED Then GUICtrlSetState($Input1, $GUI_DISABLE)
        Case $Radio_Cantik
            If GUICtrlRead($Radio_Cantik) = $GUI_CHECKED Then GUICtrlSetState($Input1, $GUI_ENABLE)
    EndSwitch
WEnd


Func _SpotRefresh()
    If _WinHttpQueryDataAvailable($hRequest) Then
        $s_Response = _WinHttpReadData($hRequest, 0, @extended)
        If Not @error Then
            Local $a_RegEx = StringRegExp($s_Response, 'spot":"(\d+\.\d+)', 1)
            If Not @error Then GUICtrlSetData($Label5, $a_RegEx[0])
        EndIf
    EndIf
EndFunc   ;==>_SpotRefresh

Func End()
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hSession)
EndFunc   ;==>End

The problem with this is: The function _WinHttpReadData() needs to much time so that the script can not handle other things (like GUI-handling) while the function executes.

I don't see now how to solve this problem in a non threadable language like AutoIt.

Edited by AspirinJunkie
Link to comment
Share on other sites

You can do it this way:

The problem with this is: The function _WinHttpReadData() needs to much time so that the script can not handle other things (like GUI-handling) while the function executes.

I don't see now how to solve this problem in a non threadable language like AutoIt.

​its too heavy..

i cant do anything else..lol

for now its better using @chimp's code to do anything else in my program (CMIIW)...

thx buddy...

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