Jump to content

How can I save this data directly into a variable?


Guest
 Share

Go to solution Solved by Guest,

Recommended Posts

Hello, Please help me to do what I want to do in this script:

#include <WinAPI.au3>
#include <Memory.au3>
#Include "ASM_Download.au3"
#Include "GUICtrlSetOnEventEx.au3"
#include <Array.au3>

#AutoIt3Wrapper_Run_AU3Check=n

Global $Array

; Create GUI window for debuging...
$Form1 = GUICreate("Form1", 376, 436, 409, 143)
$Edit1 = GUICtrlCreateEdit("", 16, 16, 345, 409)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)


; This line start a process that download the data directly to some memory address (Probably in the script pid..)
$DownloadFile  = DownloadFile("https://googledrive.com/host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html",100,True,"Name")

While 1
    $InfoArray = DownloadGetInfo($DownloadFile)
    If Not @error Then
        GUICtrlSetData($Edit1,_ArrayToString($InfoArray,@CRLF)) ; This is just to show the array data in realtime for debuging..
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd
; You nead to close the GUI when you see that $InfoArray[1] is 1. This means (when $InfoArray[1] = 1, the second line in the GUI is 1)
; that the process finished to download the page into the memory address.



; ________________________________________________________________________________________________________________________________________________________________
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Saving the data from the memory address <! Here I need help !> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Local $nBytes ; I don't know what is the purpose of this variable... but the variable will changed after _WinAPI_WriteFile($hFile,$InfoArray[9],$InfoArray[6],$nBytes)
; $InfoArray[9] is the memory address, $InfoArray[6] is the number of bytes of the data that downloaded.

; I need to use this info in order to save the data *DIRECTLY* into normal variable but I don't know how.
; The following lines make the script to: (a) read the data from the memory address -> (b) save that data into file.
; What I nead is: (a) read the data from the memory address -> save the data DIRECTLY into normal variable. I don't know how..
$hFile = _WinAPI_CreateFile(@ScriptDir & "\host-in-drive.txt",1)
_WinAPI_WriteFile($hFile,$InfoArray[9],$InfoArray[6],$nBytes)
_WinAPI_CloseHandle($hFile)

; I tried to see how _WinAPI_CreateFile working but I didn't found any useful code. it all done in the kernel32.dll.

; Please help me! Thank you!

you need to download "ASM_Download.au3" from >here

Thank you!

Edited by Guest
Link to comment
Share on other sites

 

How about just:

InetGet
_FileCreate
FileWrite

I'm currently using this approach for lack of choice.

The main reason I do not want to use this method is that it creates a temporary file on disk.

I want to read a Web page without saving a temporary file on disk in background.

I was looking for many methods and the ASM_Download.au3 seems most promising(Better then WinHttp.au3).

I am a nearly managed to do what I need ASM_Download. the example read the page in background.

now I need to know how to get it into variable directly and not as it is now(Otherwise it will be like what you suggested)

Link to comment
Share on other sites

Then skip the _filecreate and filewrite:

$html = InetGet()

Click on the inetget link (directly above), and read it's helpfile entry.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I was looking for many methods and the ASM_Download.au3 seems most promising(Better then WinHttp.au3).

I am a nearly managed to do what I need with ASM_Download. the example read the page in background.

now I need to know how to get it into variable directly and not as it is now(Otherwise it will be like what you suggested)

The _WinAPI_WriteFile() "know" how to get the data. the problem is that it save it to file and not to variable(the function does not returns the data that written to the file)

The function use the following variables to get the data:

$pBuffer = the memory address (for example 0x03E16648) which is $InfoArray[9] in the example (Returned from DownloadGetInfo())

$iToWrite = Number of bytes to be written to the file. which is $InfoArray[6]

What is needed is a way to use these inputs in order to get the data directly :)

 

Then skip the _filecreate and filewrite:

$html = InetGet()

Click on the inetget link (directly above), and read it's helpfile entry.

 

You did not understand. In any case you need to create a temporary file with InetGet.
And I do not want it.

Edited by Guest
Link to comment
Share on other sites

Yep, you are correct.

I'd use IE, and then use this one to get the html.

_IEBodyReadHTML

Or:

$html = BinaryToString(InetRead("http://www.google.com"))
ConsoleWrite($html & @CRLF)

If you know of a function that ALMOST does what you want, you can look it up in the help file, and it will be grouped with it's matching functions.  One of those will usually assist you.

The Contents tab is your friend...or the 'Related' functions section.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Yep, you are correct.

I'd use IE, and then use this one to get the html.

_IEBodyReadHTML

Or:

$html = BinaryToString(InetRead("http://www.google.com"))
ConsoleWrite($html & @CRLF)

If you know of a function that ALMOST does what you want, you can look it up in the help file, and it will be grouped with it's matching functions.  One of those will usually assist you.

 

It does not work(It should not work in my opinion). I tried this

ConsoleWrite(_IEBodyReadHTML($InfoArray[9])&@CRLF)

It returns nothing

Edited by Guest
Link to comment
Share on other sites

Read the helpfile to use _iebodyreadhtml correctly!

Use the second option I provided if you just have a URL.

...helpfile!

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Read the helpfile to use _iebodyreadhtml correctly!

Use the second option I provided if you just have a URL.

...helpfile!

If you offer me use only IE functions then I do not want it.

It forces opening hidden window of internet explorer and I don't wan't to do it with hidden internet explorer window.

With ASM_Download I don't must to open some hidden window..

It works more elegant...

Edited by Guest
Link to comment
Share on other sites

I offered you the one you need, that's outside of IE...it's right after the Or:

 

Yep, you are correct.

I'd use IE, and then use this one to get the html.

_IEBodyReadHTML

Or:

$html = BinaryToString(InetRead("http://www.google.com"))
ConsoleWrite($html & @CRLF)

If you know of a function that ALMOST does what you want, you can look it up in the help file, and it will be grouped with it's matching functions.  One of those will usually assist you.

The Contents tab is your friend...or the 'Related' functions section.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

InetRead was perfect if it could able to download in the background

InetGet was perfect if it could able to download directly to a variable

IE functions from IE.au3 was perfect if I did not have to use a separate process of internet explorer(even if hidden)

 

None of them have all the requirements which are:

1) The ability to download in the background without a separate exe

2) The ability to save directly to a variable

ASM_Download does not have the the second ability, but I believe it is possible to add this ability and it should not be a big deal .. I just do not know how to do it.
So I opened this thread .. I do not want to hear right now about other techniques.

For that I would not have to open this thread (I could just do a search)
 

But in order to know how to get the information from $InfoArray[9] and $InfoArray[6] I had to ask for help because I'm trying to figure out how to do it and I could not :)

Edited by Guest
Link to comment
Share on other sites

  • Moderators

I thought there was an _InetGetSource() function... maybe the forum has it, but it should do what you're looking to do.

Edit:

Here's one:

'?do=embed' frameborder='0' data-embedContent>>

But it doesn't exactly look like what I've used in the past.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I thought there was an _InetGetSource() function... maybe the forum has it, but it should do what you're looking to do.

Edit:

Here's one:

'?do=embed' frameborder='0' data-embedContent>>

But it doesn't exactly look like what I've used in the past.

 

This function can load the page in the background?

 

About ASM Download, if I add the following lines:

$MemOpen = _MemoryOpen(@AutoItPID)
$MemRead = _MemoryRead($InfoArray[9], $MemOpen)

ConsoleWrite($MemRead&@CRLF)

Then it return "1143028746"

It always returns the same value if you use the same URL.

 

I do not know if it's something. (You have to use NomadMemory.au3).

If I change the URL to something else then I get something different.

Then it shows that it is the right direction .. I just do not know how to proceed from here ..

Edited by Guest
Link to comment
Share on other sites

  • Moderators

It downloads the page (or even file), don't know what you mean by "load".  You want to "interact" with it in memory?

When asking in "general help", you can't assume any of us have used these udf functions or know what they do.  So there are always going to be alternatives you don't want or need thrown at you.  Sometimes you're better off posting in the original thread for help.

I did notice that _InetGetSource() is actually included in the udf's for the help file though.

As far as it working... you assume we used what you're looking for, give it a try and see if it does what you want maybe  :huh: ?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

It downloads the page (or even file), don't know what you mean by "load".  You want to "interact" with it in memory?

When asking in "general help", you can't assume any of us have used these udf functions or know what they do.  So there are always going to be alternatives you don't want or need thrown at you.  Sometimes you're better off posting in the original thread for help.

I did notice that _InetGetSource() is actually included in the udf's for the help file though.

As far as it working... you assume we used what you're looking for, give it a try and see if it does what you want maybe  :huh: ?

 

I do not know what's going on inside the function.

I roughly know what's going on outside the function

This function does what it should do (the function DownloadFile ) and that's what I need.

This function can download the page in background  without stopping the script and use temp file.

After the function has finished the job it leaves two important variables.

From that point you don't need to know nothing about how ASM Download working and you only need to know how to use these variables.

(_WinAPI_WriteFile() does not need to "know" anything about ASM Download except these variables)

The variables are:

$pBuffer  = Pointer to the buffer containing the data to be written

$iToWrite = Number of bytes to be written to the file

From these variables, the function gets the page and save it to file.

So I need to know how to get page from these variables.

Maybe you can help me how to do it?

Link to comment
Share on other sites

  • Solution

The function use the following variables to get the data:

$pBuffer = the memory address (for example 0x03E16648) which is $InfoArray[9] in the example (Returned from DownloadGetInfo())

$iToWrite = Number of bytes to be written to the file. which is $InfoArray[6]

What is needed is a way to use these inputs in order to get the data directly :)

 

Solution:

$MemOpen = _MemoryOpen(@AutoItPID)
$test = ''
For $a = 0 To $InfoArray[6]
    $MemRead = _MemoryRead($InfoArray[9]+$a, $MemOpen,'char')
    $test = $test&$MemRead
Next
ConsoleWrite($test &" (Line "&@ScriptLineNumber&")"&@CRLF)

:sorcerer:

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