Я использую этот код ниже, чтобы прочитать название и цену продукта с веб-сайта, такого как amazon, и разместить результаты в определенных ячейках Excel:
Sub Basics_Of_Web_Macro()
Dim myIE As Object
Dim myIEDoc As Object
'Start Internet Explorer
Set myIE = CreateObject("InternetExplorer.Application")
'if you want to see the window set this to True
myIE.Visible = False
'Now we open the page we'd like to use as a source for information
myIE.Navigate "https://www.amazon.com/belif-True-Cream-Aqua-Korean/dp/B00H4GOAZO/ref=pd_cart_crc_cko_cp_2_2/139-8277217-3794320?_encoding=UTF8&pd_rd_i=B00H4GOAZO&pd_rd_r=e154e278-8a11-4ab0-8173-5d0dbaff1938&pd_rd_w=Hm8FW&pd_rd_wg=Hpv4X&pf_rd_p=eff166ab-25d2-4f2c-a51d-0a0e86061f9d&pf_rd_r=EVT26E6K7CV8T1QMTY7H&psc=1&refRID=EVT26E6K7CV8T1QMTY7H"
'We wait for the Explorer to actually open the page and finish loading
While myIE.Busy
DoEvents
Wend
'Now lets read the HTML content of the page
Set myIEDoc = myIE.Document
'Time to grab the information we want
'We'll start with the Title of the page
Range("A1") = myIEDoc.Title
'Then we'll get something from the inner page content by using the ID
Range("B1") = myIEDoc.getElementById("priceblock_ourprice").innerText
End Sub
Часть "title" извлекается, как ожидается, и помещается в ячейку A1, но часть для извлечения "цены" и помещения ее в ячейку B1 не работает. Что я делаю не так?
Кроме того, я хотел бы извлечь данные из выпадающего меню, чтобы выбрать количество элементов на странице, например, выбрать 3 из выпадающего меню?