PC Review


Reply
Thread Tools Rate Thread

Automating download of csv files from web

 
 
=?Utf-8?B?cm9iczMxMzE=?=
Guest
Posts: n/a
 
      25th May 2007
Hi,

I wanted to get direction on how to automate the dowload of CSV files from a
website. Below are the details on where the CSV files are located within the
website:

- The website requires a login and password
- There is one web page within the site that has 50 or so links which when
clicked on, result in data being displayed in a tabular format. On this
output page, there is also a "Download File" link which allows you to
download the data in CSV format.
- I have created a .xls file that I would like to create a macro within so
that it can do the following:
1 - Automate the clicking on each of the 50 links which contain the
tabular data
2 - Automate the clicking of the "Download Data" link which appears on
the output page of each of the 50 aforementioned links (note that when this
link is clicked, it gives you three download options, one of which is to
download the file in CSV format, which is the one I would like to have
selected)
3 - When the download button is clicked, automate the clicking of the
"Open" button when the popup comes up asking if you'd like to Open or Save
the file.

All subsequent steps I can handle -- it's just these first three steps where
I'm getting stuck -- and in researching this, unfortunately, I haven't found
any clear direction as of yet.

FYI - I've tried using Web Query to pull the data directly from the table
that shows on the web page when each of the 50 links is clicked, however, the
web query was not able to use the URL I entered I'm guessing either because
of security or because of it's length. Anyway, the 50 or so links on the
page are updated weekly with some new links showing up each week. It seems
that automating the dowload of the CSV files would be a more reliable
solution than using web queries (if not, please don't hesitate to let me know
your opinion!).

Finally, once I develop this spreadsheet, there will be a number of
different users using it -- I'm wondering if the fact that not everyone will
be using Internet Explorer will create a problem in coming up with a solution
here...if so, you can assume I will just create a solution for IE.


Thanks so much in advance for any help you can provide!


--
Robert
 
Reply With Quote
 
 
 
 
Dave Miller
Guest
Posts: n/a
 
      25th May 2007
This question is a very website specific question:

-Is the password a "Pop-up" input box?
if so, your URL should read "HTTP://
username(E-Mail Removed)"

or embedded in the HTML?
if so, you would need to locate either the name of these text boxes
or the ID to be used in the code:

for example:

Sub SignIn()
Dim ie As Object
Dim sLinks() As String
Dim i As Integer

Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
.navigate "HTTP://www.d-miller.com"
Do Until .readystate = 4
DoEvents
Loop
With .document
With .Forms(0)
.Item("UserName") = "YourUserName"
.Item("Password") = "YourPassword"
.Submit
End With
Do While ie.Busy
DoEvents
Loop
With .Links
For i = 0 To .Length - 1
ReDim Preserve sLinks(i) As String
sLinks(i) = .Item(i).href
Next
End With
End With

For i = 0 To UBound(sLinks)
.navigate sLinks(i)
Do Until .readystate = 4
DoEvents
Loop
With .document.all
For j = 0 To .Length
With .Item(j)
If .nodeName Like "TABLE" Then
With .Rows
For l = 0 To .Length - 1
With .Item(l).Cells
For c = 0 To .Length - 1
With .Item(c)
ActiveSheet.Cells(l +
1, c + 1) = .innerText
End With
Next
End With
Next
End With
End If
End With
Next j
End With
Next
End With
End Sub

 
Reply With Quote
 
Dave Miller
Guest
Posts: n/a
 
      25th May 2007
This question is a very website specific question with many factors:

-Is the password a "Pop-up" input box?
if so, your URL should read "HTTP://
username(E-Mail Removed)"

or embedded in the HTML?
if so, you would need to locate either the name of these text boxes
or the ID to be used in the code:

for example:

Sub SignIn()
Dim ie As Object
Dim sLinks() As String
Dim i As Integer

Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
.navigate "HTTP://www.YourSiteNameHere.com"
Do Until .readystate = 4
DoEvents
Loop
With .document
With .Forms(0)
.Item("UserName") = "YourUserName"
.Item("Password") = "YourPassword"
.Submit
End With
Do While ie.Busy
DoEvents
Loop
With .Links
For i = 0 To .Length - 1
ReDim Preserve sLinks(i) As String
sLinks(i) = .Item(i).href
Next
End With
End With

For i = 0 To UBound(sLinks)
.navigate sLinks(i)
Do Until .readystate = 4
DoEvents
Loop
With .document.all
For j = 0 To .Length
With .Item(j)
If .nodeName Like "TABLE" Then
With .Rows
For l = 0 To .Length - 1
With .Item(l).Cells
For c = 0 To .Length - 1
With .Item(c)
ActiveSheet.Cells(l +
1, _
c +
1) = _
.innerText
End With
Next
End With
Next
End With
End If
End With
Next j
End With
Next
End With
End Sub

 
Reply With Quote
 
=?Utf-8?B?cm9iczMxMzE=?=
Guest
Posts: n/a
 
      26th May 2007
Thanks so much Dave! I'm going to spend some time with this and will enter
another post if there is something I can't figure out. Thanks for your input!

--
Robert


"Dave Miller" wrote:

> This question is a very website specific question with many factors:
>
> -Is the password a "Pop-up" input box?
> if so, your URL should read "HTTP://
> username(E-Mail Removed)"
>
> or embedded in the HTML?
> if so, you would need to locate either the name of these text boxes
> or the ID to be used in the code:
>
> for example:
>
> Sub SignIn()
> Dim ie As Object
> Dim sLinks() As String
> Dim i As Integer
>
> Set ie = CreateObject("InternetExplorer.Application")
>
> With ie
> .Visible = True
> .navigate "HTTP://www.YourSiteNameHere.com"
> Do Until .readystate = 4
> DoEvents
> Loop
> With .document
> With .Forms(0)
> .Item("UserName") = "YourUserName"
> .Item("Password") = "YourPassword"
> .Submit
> End With
> Do While ie.Busy
> DoEvents
> Loop
> With .Links
> For i = 0 To .Length - 1
> ReDim Preserve sLinks(i) As String
> sLinks(i) = .Item(i).href
> Next
> End With
> End With
>
> For i = 0 To UBound(sLinks)
> .navigate sLinks(i)
> Do Until .readystate = 4
> DoEvents
> Loop
> With .document.all
> For j = 0 To .Length
> With .Item(j)
> If .nodeName Like "TABLE" Then
> With .Rows
> For l = 0 To .Length - 1
> With .Item(l).Cells
> For c = 0 To .Length - 1
> With .Item(c)
> ActiveSheet.Cells(l +
> 1, _
> c +
> 1) = _
> .innerText
> End With
> Next
> End With
> Next
> End With
> End If
> End With
> Next j
> End With
> Next
> End With
> End Sub
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automating the conversion of CSV files to XLSX files Chris Microsoft Excel Programming 3 28th Nov 2007 09:35 PM
IE 6.0 Unable to Download files - Attempting to When you attempt to download a file from a Web site, the Copying dialog box may appear ... Internet Explorer Window Closes When You Click a Download Link . Robert Cox Windows XP Internet Explorer 6 5th Sep 2007 09:08 PM
Automating photo and video download from peripheral devices =?Utf-8?B?V2hhdERvWW91TWVhblBpZ3NDYW50Rmx5Pw==?= Windows XP WMI 0 14th Dec 2005 07:14 PM
Automating download of emails Paul Microsoft Outlook Discussion 1 8th Apr 2004 07:18 PM
Automating download Bhalchandra Windows XP Internet Explorer 0 24th Dec 2003 07:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:36 PM.