无法在 Web 提取上设置父级 Class
Can Not Set Parent Class on Web Extraction
我在设置正确的父级 class 以从 AliExpress 提取一些数据时遇到问题。我尝试了几种变体,有些只提取一行信息,我能做的最好的就是提取 8 行数据。通常我只需要设置一个父 class,但是为此我无法计算出父 class 它是一个 Div Class
和 ul Class
一个 div没有名字 Div
然后是 Li Class
link: https://www.aliexpress.com/af/phones.html?trafficChannel=af&d=y&CatId=0&SearchText=phones<ype=affiliate&SortType=default&g=y
''counter
myCounter = myCounter + 1
Worksheets("Sheet20").Range("B6").Value = myCounter
'Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set html = objIE.document
Set elements = html.getElementsByClassName("gallery product-card middle-place") ' parent CLASS
'FOR LOOP
For Each element In elements
DoEvents
''' Element 1
DoEvents
If element.getElementsByClassName("item-title-wrap")(0).getElementsByTagName("a")(0) Is Nothing Then ' Get CLASS and Child Nod
wsSheet.Cells(sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1, "A").Value = "-" 'If Nothing then Hyphen in CELL
Else
htmlText = element.getElementsByClassName("item-title-wrap")(0).getElementsByTagName("a")(0).href 'Get CLASS and Child Nod
wsSheet.Cells(sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1, "A").Value = htmlText 'return value in column
End If
''' Element 2
DoEvents
If element.getElementsByClassName("item-title-wrap")(0) Is Nothing Then ' Get CLASS and Child Nod
wsSheet.Cells(sht.Cells(sht.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = "-" 'If Nothing then Hyphen in CELL
Else
htmlText = element.getElementsByClassName("item-title-wrap")(0).innerText ' Get CLASS and Child Nod 'src
wsSheet.Cells(sht.Cells(sht.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = htmlText 'return value in column
End If
''' Element 3
结果,我只能拉出大约8行数据
Q) 有人可以建议如何设置父级 Class,在这里? 我想坚持我的代码,因为我在 VBA 中受到限制,我确实理解我的代码
Set Html = objIE.document
Set elements = Html.getElementsByClassName("gallery product-card middle-place") ' parent
一如既往地提前致谢。
Can someone please advise on how to set the Parent Class, Here?
不需要家长。目标元素都具有相同的 class 名称,因此使用 list-item 然后循环返回集合。
Set elements = Html.getElementsByClassName("list-item")
I can only pull off about 8 rows of data
页面延迟加载,您需要滚动页面才能获取更多元素。如果您在 lazy loading/scrolling 上搜索现有答案,您应该会找到许多现有的好例子。他们依赖于相同的基本策略,VBA 例如
中应用的并不多
- 按给定高度继续滚动 window 并计算目标元素。当 n 次滚动的目标元素数没有增加时停止。
- 在页面底部找到一个元素并将其滚动到视口中。
这是否有效是可变的。取决于页面设置。在上面的场景 1 中经常用作滚动高度。
等等.......
或者,使用浏览器网络选项卡监控网络流量,滚动时查看是否可以在网络选项卡中找到任何其他请求并复制这些 xhrs 以获取其他数据。
我在设置正确的父级 class 以从 AliExpress 提取一些数据时遇到问题。我尝试了几种变体,有些只提取一行信息,我能做的最好的就是提取 8 行数据。通常我只需要设置一个父 class,但是为此我无法计算出父 class 它是一个 Div Class
和 ul Class
一个 div没有名字 Div
然后是 Li Class
link: https://www.aliexpress.com/af/phones.html?trafficChannel=af&d=y&CatId=0&SearchText=phones<ype=affiliate&SortType=default&g=y
''counter
myCounter = myCounter + 1
Worksheets("Sheet20").Range("B6").Value = myCounter
'Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Set html = objIE.document
Set elements = html.getElementsByClassName("gallery product-card middle-place") ' parent CLASS
'FOR LOOP
For Each element In elements
DoEvents
''' Element 1
DoEvents
If element.getElementsByClassName("item-title-wrap")(0).getElementsByTagName("a")(0) Is Nothing Then ' Get CLASS and Child Nod
wsSheet.Cells(sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1, "A").Value = "-" 'If Nothing then Hyphen in CELL
Else
htmlText = element.getElementsByClassName("item-title-wrap")(0).getElementsByTagName("a")(0).href 'Get CLASS and Child Nod
wsSheet.Cells(sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1, "A").Value = htmlText 'return value in column
End If
''' Element 2
DoEvents
If element.getElementsByClassName("item-title-wrap")(0) Is Nothing Then ' Get CLASS and Child Nod
wsSheet.Cells(sht.Cells(sht.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = "-" 'If Nothing then Hyphen in CELL
Else
htmlText = element.getElementsByClassName("item-title-wrap")(0).innerText ' Get CLASS and Child Nod 'src
wsSheet.Cells(sht.Cells(sht.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = htmlText 'return value in column
End If
''' Element 3
结果,我只能拉出大约8行数据
Q) 有人可以建议如何设置父级 Class,在这里? 我想坚持我的代码,因为我在 VBA 中受到限制,我确实理解我的代码
Set Html = objIE.document
Set elements = Html.getElementsByClassName("gallery product-card middle-place") ' parent
一如既往地提前致谢。
Can someone please advise on how to set the Parent Class, Here?
不需要家长。目标元素都具有相同的 class 名称,因此使用 list-item 然后循环返回集合。
Set elements = Html.getElementsByClassName("list-item")
I can only pull off about 8 rows of data
页面延迟加载,您需要滚动页面才能获取更多元素。如果您在 lazy loading/scrolling 上搜索现有答案,您应该会找到许多现有的好例子。他们依赖于相同的基本策略,VBA 例如
中应用的并不多- 按给定高度继续滚动 window 并计算目标元素。当 n 次滚动的目标元素数没有增加时停止。
- 在页面底部找到一个元素并将其滚动到视口中。 这是否有效是可变的。取决于页面设置。在上面的场景 1 中经常用作滚动高度。
等等.......
或者,使用浏览器网络选项卡监控网络流量,滚动时查看是否可以在网络选项卡中找到任何其他请求并复制这些 xhrs 以获取其他数据。