我正在使用以下代码从亚马逊之类的网站上读取产品的标题和价格,并将结果放在特定的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
“标题”部分已按预期提取并放置在单元格A1中,但是提取“价格”并将其放置在单元格B1中的部分无效。我在做什么错了?
此外,我想从下拉菜单中提取数据以从页面中选择项目数量,例如,从下拉菜单中选择3?