简体   繁体   中英

Extract Table from Webpage

I am going to extract table having like "Date|Open|High|Low|Close|No.of Shares|No.of trades|Total Turnover|Deliverable Qty" on Web page " https://www.bseindia.com/markets/equity/EQReports/StockPrcHistori.aspx?expandable=7&scripcode=503100&flag=sp&Submit=G "

Below are my codes:

Sub Macro_BSE()


  Application.ScreenUpdating = False

  Dim FileName, Pathname As String

    MP = ActiveWorkbook.Name

    Workbooks.Add
    WB2 = ActiveWorkbook.Name

    Dim IE As New SHDocVw.internetexplorer

    Const MAX_WAIT_SEC As Long = 5
    Dim frm As Variant
    Dim element, submitInput As Variant
    Dim rowCollection, htmlRow As Variant
    Dim rowSubContent, rowSubData As Variant
    Dim anchorRange As Range, cellRng As Range
    Dim start
    Dim A As String
    Dim hTable As HTMLTable
    Dim clipboard As Object

    IE.Visible = True
    IE.navigate "https://www.bseindia.com/markets/equity/EQReports/StockPrcHistori.aspx?expandable=7&scripcode=503100&flag=sp&Submit=G"
    While IE.readyState <> 4: DoEvents: Wend

       Application.Wait (Now + TimeValue("00:00:02"))

    IE.document.querySelector("#ContentPlaceHolder1_rdbDaily").Click

    IE.document.querySelector("[name='ctl00$ContentPlaceHolder1$txtFromDate']").Value = "28/11/2018"
    IE.document.querySelector("[name='ctl00$ContentPlaceHolder1$txtToDate']").Value = "28/12/2018"
    IE.document.querySelector("[name='ctl00$ContentPlaceHolder1$btnSubmit']").Click

    Application.Wait (Now + TimeValue("00:00:10"))

     T = Timer
        Do
            On Error Resume Next
            Set hTable = IE.document.querySelector("#ContentPlaceHolder1_spnStkData table")
            On Error GoTo 0
            If Timer - T > MAX_WAIT_SEC Then Exit Do
        Loop While hTable Is Nothing
        If Not hTable Is Nothing Then
            clipboard.SetText hTable.outerHTML
            clipboard.PutInClipboard
            Workbooks(WB2).Worksheets("Sheet1").Range("A1").PasteSpecial

        End If

End Sub

I am not able to extract that table as of now. Earlier i was able to extract from same code

Kindly Suggest the changes

You never create an instance of the clipboard object. Do so before attempting to put text into it.

Set clipboard = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
clipboard.SetText hTable.outerHTML

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM