Точка VBA не найдена. дело в картинке - PullRequest
0 голосов
/ 03 октября 2019
Option Explicit
Public Sub GetClosePrice()
    Dim ws As Worksheet, re As Object, p As String, r As String

    Set ws = ThisWorkbook.Worksheets("Sheet1")
    p = """pe_details[enter image description here][1]"":""(.*?)"""
    Set re = CreateObject("VBScript.RegExp")

    With CreateObject("MSXML2.XMLHTTP")
            .Open "GET", "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=HAL", False
            .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
            .send
            If .Status = 200 Then
                r = GetValue(re, .responseText, p)
            Else
                r = "Failed connection"
            End If
    End With
    ws.Range("K11").Value = r
End Sub

Public Function GetValue(ByVal re As Object, ByVal inputString As String, ByVal pattern As String) As String
    With re
        .Global = True
        .pattern = pattern
        If .test(inputString) Then  ' returns True if the regex pattern can be matched agaist the provided string
            GetValue = .Execute(inputString)(0).submatches(0)
        Else
            GetValue = "Not found"
        End If
    End With
End Function

enter image description here

1 Ответ

0 голосов
/ 03 октября 2019

Если вам нужен P / E, вы можете попробовать это: enter image description here

    Set o = CreateObject("MSXML2.XMLHTTP")
    With o
      .Open "GET", "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/getPEDetails.jsp?symbol=HAL"
      .send
      If .Status = 200 Then
          r = .responseText
      Else
          r = "Failed connection"
      End If
    End With

, поэтому ваша переменная 'r' будет иметь ответ json. Затем вам нужно извлечь данные из него.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...