提问人:Peter Yun 提问时间:10/29/2023 最后编辑:Peter Yun 更新时间:10/29/2023 访问量:88
我尝试了各种元素搜索方法,如 class、name 和 id,但它不起作用
i've tried various element search methods like class, name, and id, but it's not working
问:
我一直在尝试使用 WinHTTP 进行 Excel Web 抓取,并且尝试了各种元素搜索方法,例如 class、name 和 id,但它不起作用。抓取在其他网站上有效,但在此网站上效果不佳。我想抓取的是产品名称和图片的URL。谁能帮忙? 代码如下
Sub WebScrapingWithWinHTTP()
Dim objWinHTTP As Object
Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url As String
url = "https://www.outre.com/new/"
objWinHTTP.Open "GET", url, False
objWinHTTP.send
Dim html As String
html = objWinHTTP.responseText
Dim htmlDoc As Object
Set htmlDoc = CreateObject("htmlfile")
htmlDoc.body.innerHTML = html
Dim elements As Object
Set elements = htmlDoc.getElementsByClassName("uppercase.font-bold.text-[16px].xs:text-[1.3vw].lg:text-[14px]")
If elements.Length > 0 Then
Dim element As Object
Set element = elements.Item(1)
Dim title As String
title = element.innertext
Sheets("Sheet1").Range("A1").Value = title
Else
Sheets("Sheet1").Range("A1").Value = "nothing"
End If
Set objWinHTTP = Nothing
Set htmlDoc = Nothing
End Sub
答: 暂无答案
评论