Multiple Table download from the internet to Excel Yahoo Finance Japan

gilesgerman

New Member
Joined
Dec 19, 2017
Messages
8
Dear All,

I hope you can help me I am trying to download historical share data for share 8088 from yahoo Japan.

The first page of the table I need is in the following location: - https://info.finance.yahoo.co.jp/hi...1983&sm=11&sd=19&ey=2017&em=12&ed=19&tm=d&p=1

I then want to download all the share data the above is 1~20件/8554件中 as you will see in the top left corner.

The final page is page 428 at the following URL....

https://info.finance.yahoo.co.jp/hi...83&sm=11&sd=19&ey=2017&em=12&ed=19&tm=d&p=428

I am looking to get all these pages from 1-428 into excel on a single sheet so I can complete this analysis.

Giles
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
The following code will do what you asked for, but you will have some cleanup to do. I set it to extract pages 1 to 428. I understand that some sites prevent more than a certain number of downloads in a set short time (e.g., 50 queries per hour). If this is the case you will have to changes this line:

For lPage = 1 To 428 'Manually set page range

to get the pages you want.

That page has 3 tables and your data is in table 2. If you want all of the tables comment out the If tabno = 2 Then line and its corresponding End If line

Code:
Option Explicit

Sub ExtractDataFromTables()
    'Modification of
    'http://www.mrexcel.com/forum/excel-questions/259738-general-q-regarding-using-visual-basic-applications-xl-pass-through-ie.html
    
    Dim ie As Object
    Dim myTextField
    Dim doc     'Variant/Object/HTMLDocument
    Dim lPage As Long
    
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        For lPage = 1 To 428   'Manually set page range
            .Visible = True
            '.navigate "http://eoddata.com/stockquote/NASDAQ/AAPL.htm"
            .navigate "https://info.finance.yahoo.co.jp/history/?code=8088.T&sy=1983&sm=11&sd=19&ey=2017&em=12&ed=19&tm=d&p=" & lPage
            Do Until .readyState = 4: DoEvents: Loop
    '        Set myTextField = .Document.all.Item("series_id")
    '        myTextField.Value = "ECU11121I"
    '        ie.Document.Forms(0).submit
    '        Do Until .ReadyState = 4: DoEvents: Loop
    '        Do While .Busy: DoEvents: Loop
            Set doc = ie.document
            GetAllTables doc
        Next
        .Quit
    End With
    
    Set doc = Nothing
    Set ie = Nothing
    
End Sub

Sub GetAllTables(d)

    Dim e   'Variant/Object/HTMLTable
    Dim t   'Variant/Object/HTMLTable
    Dim tabno As Long
    Dim nextrow As Long
    Dim Rng As Range
    Dim R   'Variant/Object/HTMLTableRow
    Dim c   'Variant/Object/HTMLTableCell
    Dim i As Long
    
    For Each e In d.all
        If e.nodeName = "TABLE" Then
            Set t = e
    
            tabno = tabno + 1
            If tabno = 2 Then
                nextrow = Cells(Rows.Count, 2).End(xlUp).Row + 1
                Set Rng = Range("B" & nextrow)
                Rng.Offset(, -1) = "Table " & tabno
                For Each R In t.Rows
                    For Each c In R.Cells
                        Rng.Value = c.innerText
                        Set Rng = Rng.Offset(, 1)
                        i = i + 1
                    Next c
                    nextrow = nextrow + 1
                    Set Rng = Rng.Offset(1, -i)
                    i = 0
                Next R
            End If
        End If
    Next e
    
    Set Rng = Nothing
    Set t = Nothing
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top