Jump to content
Sign in to follow this  
TobiFX

Download data from the Internet

Recommended Posts

TobiFX

Hello AutiIt Forum,

I'm new to this forum and new to AutoIt. Unfortunately I don't have any experince in programing at all so you might be so kind to help me with my two problems.

Problem 1:

I would like to automate the download of the following file and save it to C:\Test\

http://www.cboe.com/publish/ScheduledTask/...use/totalpc.csv

Problem 2:

I would like to copy the data in the following chart and save it in an Excel file.

http://online.wsj.com/mdc/public/page/2_30..._h_usshlUsually

The data I would like to copy are the first 9 rows and the 5 columns of the top "NYSE" section.

The name of the Excel file were I would like to copy the data to is named/stored C:\Test\NYSE_Data.xls. The data should be stored in the Excel-sheet named "NYSE-Internals".

As mentioned above, I don't have any experince so I'd really appriciate if you could give me the whole scripts. I'll try to learn from there.

If you need any further information, please let me know.

Thanks in advance,

Tobi

Share this post


Link to post
Share on other sites
TobiFX

Little additional information on Problem 1:

The downloaded file should either be saved as csv or txt file.

Share this post


Link to post
Share on other sites
TobiFX

Hello rasim,

thanks for your welcome and your help.

I was hoping for a script or a little more detailed information. But ... for Problem 1 I got it done, thanks to your hint.

Here's how the script looks like, if any other newbie is wondering:

InetGet("http://www.cboe.com/publish/ScheduledTask/MktData/datahouse/totalpc.csv", "C:\Test\Datadownload.csv", 1, 0)

So Problem 1) is solved.

Looking forward to solutions for Problem 2). I'd appriciate more detailed information (ideally a script), since that seems to be much more complicated.

Thanks for anyone's help,

Tobi

Share this post


Link to post
Share on other sites
ToyBoi

I had a similar situation and here's my partial code for this part

#include <GuiConstants.au3>
#include <IE.au3>
#include <File.au3>
#include <ExcelCOM_UDF.au3> 
#include <Array.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

$Address = "C:\Documents and Settings\" & @UserName & "\Desktop\" & @MON & "." & @MDAY & "." & @YEAR
DirCreate($Address ) 

$oExcel = _ExcelBookNew(1)
_ExcelBookSaveAs($oExcel, $Address & "\1", "xls", 0, 1)



$oTable = _IETableGetCollection ($oIE, 39)
$aTableData = _IETableWriteToArray ($oTable, True)
    
;goes to excel, and activates the right page
;goes to excel, and activates the right page
    
    
WinActivate("[TITLE:Microsoft Excel]", "")
_ExcelSheetActivate($oExcel, $Freq[$i])
        
;pastes the right table into the right page
_ExcelWriteSheetFromArray($oExcel, $aTableData, 1, 1, 0, 0)
sleep(300)
WinActivate("[TITLE:SciCare Retriever]", "")
sleep(300)

$oTable = _IETableGetCollection ($oIE, 39), this line here gets the table from the site, in my case there were 40 different tables on that site, you kind of have to do it by trial and error, and see which number corresponds to your table.

also don't forget to dl this UDF from this link http://www.autoitscript.com/forum/index.ph...mp;hl=excel+udf

this lets you use excel and the function _ExcelWriteSheetFromArray($oExcel, $aTableData, 1, 1, 0, 0), which will output the table into your excel sheet.

use the functions $oIE = _IECreate()

_IELoadWait ($oIE)

_IENavigate($oIE, "your url")

to get to the site

Share this post


Link to post
Share on other sites
TobiFX

Hello ToyBoi, hello everyone!

First of all thanks a lot for your message.

But ... this is way to complicated for me to get this things running the way I would like to.

I've downloaded the "ExcelCOM_UDF.au3" file and saved it to the "\AutoIt3\Include" directory. I've also implemented the "$oIE = _IECreate() ..." lines with the website I'm looking at.

When I go through the script (F5) - ignoring the error messages - Excel opens up with a new/empty file and the IE starts with the correct website.

PLEASE anyone help me to get this thing running.

Below you'll find the current code and the error messages.

Thanks for any additional help - ideally a script that is working ;-)

Regards,

Tobi

Spript:

#include <GuiConstants.au3>

#include <IE.au3>

#include <File.au3>

#include <ExcelCOM_UDF.au3>

#include <Array.au3>

#include <GUIComboBox.au3>

#include <GuiConstantsEx.au3>

#include <Constants.au3>

$Address = "C:\Documents and Settings\" & @UserName & "\Desktop\" & @MON & "." & @MDAY & "." & @YEAR

DirCreate($Address )

$oExcel = _ExcelBookNew(1)

_ExcelBookSaveAs($oExcel, $Address & "\1", "xls", 0, 1)

$oIE = _IECreate()

_IELoadWait ($oIE)

_IENavigate($oIE, "http://online.wsj.com/mdc/public/page/2_3021-tradingdiary.html?mod=mdc_h_usshlUsually")

$oTable = _IETableGetCollection ($oIE, 39)

$aTableData = _IETableWriteToArray ($oTable, True)

;goes to excel, and activates the right page

;goes to excel, and activates the right page

WinActivate("[TITLE:Microsoft Excel]", "")

_ExcelSheetActivate($oExcel, $Freq[$i])

;pastes the right table into the right page

_ExcelWriteSheetFromArray($oExcel, $aTableData, 1, 1, 0, 0)

sleep(300)

WinActivate("[TITLE:SciCare Retriever]", "")

sleep(300)

Error Messages:

\test.au3(28,38) : WARNING: $i: possibly used before declaration.

_ExcelSheetActivate($oExcel, $Freq[$i]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

\test.au3(28,39) : WARNING: $Freq: possibly used before declaration.

_ExcelSheetActivate($oExcel, $Freq[$i])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

\test.au3(28,38) : ERROR: $i: undeclared global variable.

_ExcelSheetActivate($oExcel, $Freq[$i]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

\test.au3 - 1 error(s), 2 warning(s)

Share this post


Link to post
Share on other sites
TobiFX

Hello everyone,

just wanted to ask if someone read my post and can help me on Problem 2.

Thanks,

Tobi

Share this post


Link to post
Share on other sites
ToyBoi

#include <GuiConstants.au3>

#include <IE.au3>

#include <File.au3>

#include <ExcelCOM_UDF.au3>

#include <Array.au3>

#include <GUIComboBox.au3>

#include <GuiConstantsEx.au3>

#include <Constants.au3>

$Address = "C:\Documents and Settings\" & @UserName & "\Desktop\" & @MON & "." & @MDAY & "." & @YEAR

DirCreate($Address )

$oExcel = _ExcelBookNew(1)

_ExcelBookSaveAs($oExcel, $Address & "\1", "xls", 0, 1)

$oIE = _IECreate()

_IELoadWait ($oIE)

_IENavigate($oIE, "http://online.wsj.com/mdc/public/page/2_3021-tradingdiary.html?mod=mdc_h_usshlUsually")

$oTable = _IETableGetCollection ($oIE, 39)

$aTableData = _IETableWriteToArray ($oTable, True)

;goes to excel, and activates the right page

;goes to excel, and activates the right page

WinActivate("[TITLE:Microsoft Excel]", "")

_ExcelSheetActivate($oExcel, $Freq[$i])

;pastes the right table into the right page

_ExcelWriteSheetFromArray($oExcel, $aTableData, 1, 1, 0, 0)

sleep(300)

WinActivate("[TITLE:SciCare Retriever]", "")

sleep(300)

lol sorry that was my code you were supposed to change it up a bit for your situation. the error said you don't have the $i variable declared, which you don't need in your situation.

#include <GuiConstants.au3>
#include <IE.au3>
#include <File.au3>
#include <ExcelCOM_UDF.au3>
#include <Array.au3>
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

$Address = "C:\Test\"
DirCreate($Address )

$oExcel = _ExcelBookNew(1)
_ExcelBookSaveAs($oExcel, $Address & "NYSE_Data", "xls", 0, 1)

_ExcelSheetAddNew($oExcel, "NYSEInternals")
_ExcelSheetDelete($oExcel, "Sheet1", False)
_ExcelSheetDelete($oExcel, "Sheet2", False)
_ExcelSheetDelete($oExcel, "Sheet3", False)

$oIE = _IECreate("about:blank",0,0)
_IELoadWait ($oIE)
_IENavigate($oIE, "http://online.wsj.com/mdc/public/page/2_3021-tradingdiary.html?mod=mdc_h_usshlUsually")

$oTable = _IETableGetCollection ($oIE, 11)
$aTableData = _IETableWriteToArray ($oTable, True)

;goes to excel, and activates the right page
;goes to excel, and activates the right page

WinActivate("[TITLE:Microsoft Excel]", "")
Winwaitactive("[TITLE:Microsoft Excel]")
;pastes the right table into the right page
_ExcelWriteSheetFromArray($oExcel, $aTableData, 1, 1, 0, 0)
sleep(300)
_ExcelBookSaveAs($oExcel, $Address & "NYSE_Data", "xls", 0, 1)
_IEQuit ($oIE)
_ExcelBookClose($oExcel)

Here it should work perfectly now, i tested it myself. In the future it is best if you referred to the AutoIt help file for assistance and came up with some of your own code first. I know it can be hard to learn it at first, but the AutoIt help file is very good and most function have working examples that you can try.

Share this post


Link to post
Share on other sites
TobiFX

Hi ToyBoi,

thanks a million for your help. That's exactly the way I wanted it.

I'll go from there and will look at the help file at first in the future to try to come up with my own code.

Have a great weekend,

Tobi

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.