我有一个包含以下html部分的url
<div class="shop cf">
<a class="shop-logo js-shop-logo" href="/m/3870/GMobile">
<noscript>
<img alt="GMobile" class="js-lazy" data-src="//a.scdn.gr/ds/shops/logos/3870/mid_20160920155600_71ff515d.jpeg" src="//a.scdn.gr/ds/shops/logos/3870/mid_20160920155600_71ff515d.jpeg" />
</noscript>
<img alt="GMobile" class="js-lazy" data-src="//a.scdn.gr/ds/shops/logos/3870/mid_20160920155600_71ff515d.jpeg" src="//c.scdn.gr/assets/transparent-325472601571f31e1bf00674c368d335.gif" />
</a>
</div>我想在div类shop cf中获得第一个img alt,我做到了。
Set seller = Doc.querySelectorAll("img")
wks.Cells(i, "D").Value = seller.getAttribute("alt").Content(0)我什么也得不到,我忘了包括?!?
我能从哪里得到它吗?
<noscript>标签?
我也尝试了下面的方法
Set seller = Doc.getElementsByClassName("js-lazy")
wks.Cells(i, "D").Value = seller.getAttribute("alt")发布于 2018-12-18 00:32:49
将元素与属性选择器一起使用
CSS:
img[alt]VBA:
ie.document.querySelector("img[alt]")您可能需要添加
ie.document.querySelector("img[alt]").getAttribute("alt")若要包含类,请使用
ie.document.querySelector("img.js-lazy[alt]")如果有多个元素,则使用querySelectorAll并索引返回的nodeList,例如
Set list = ie.document.querySelectorAll("img.js-lazy[alt]")
list.item(0).getAttribute('alt')
list.item(1).getAttribute('alt')发布于 2020-01-20 18:42:53
你试过这种方法吗?
let lazy1 = document.querySelectorAll(".js-lazy")[0]
let lazyalt = lazy1.getAttribute("alt");
let shop = document.querySelector('.shop');
shop.classList.add(lazyalt);
console.log(lazyalt)https://stackoverflow.com/questions/53816918
复制相似问题