简体   繁体   中英

how to get value within java script tag in VBA

I hope you will be fine by the grace of God. As I get some values like price of an Item from a website successfully. But I am unable to get value like Seller ID="" which is in Script Tags. May I find this value through REGEX or something else. Please help.

Sub Test()
'Declaration
Dim ie As InternetExplorer
Dim ht As HTMLDocument

'Initialization
Set ie = New InternetExplorer
ie.navigate ("")
ie.Visible = True
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = ie.document
Dim sDD As String
sDD = Doc.getElementsByClassName("pdp-product-price")(0).getElementsByTagName("span")(0).innerText
MsgBox sDD

End Sub

Try this

Sub Test()
    Dim ie As InternetExplorer, doc As HTMLDocument, sDD As String, sHTML As String
    Set ie = New InternetExplorer
    ie.Navigate ("https://www.daraz.pk/products/2019-kitchen-silicone-five-pointed-star-sink-filter-bathroom-floor-drains-shower-hair-sewer-filter-colanders-strainer-i132120426-s1292321303.html?spm=a2a0e.searchlist.list.62.50ac38869NB6RG&search=1")
    ie.Visible = True
    Do
        DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
    Set doc = ie.document
    sDD = doc.getElementsByClassName("pdp-product-price")(0).getElementsByTagName("span")(0).innerText
    Debug.Print sDD
    sHTML = doc.body.outerHTML
    Debug.Print Split(Split(sHTML, "seller_id=")(1), "&")(0)
End Sub

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