如何使用 VBA/selenium/chrome 查找 href 属性?
How to find the href attribute using VBA/selenium/chrome?
我对网络抓取相当陌生,我在 VBA/Excel 中使用 Chrome 开始使用 Selenium。我的目标元素是菜单项。
在某些网站上我可以找到这些元素,但我找不到它们 "href"。这里是destination website。我想要页面右侧菜单项的"href"。
这是我试过的:
' geting the menus, working well:
Set mnus = bot1.FindElementsByClass("topmenu")
MenuCounter = 0
For Each mnu In mnus
'getting the href, fails
lnk = mnu.Attribute("href")
我也尝试了其他一些方法,但没有成功。
这是检查的屏幕截图:
请注意,我不仅需要这个特定元素的 href(其 href 是 "art")。我还想要其他等效菜单项的 href(第一项除外)。
href 值在锚标记内 不是 li element.You 需要在 css 选择器之后定位锚 tag.Use。
Set mnus = bot1.FindElementsByCssSelector("li.topmenu >a[href]")
MenuCounter = 0
For Each mnu In mnus
lnk = mnu.Attribute("href")
或者要获取所有菜单 link 试试这个。
获取所有菜单link
Set mnus = bot1.FindElementsByCssSelector("ul.topmenu a[href]")
MenuCounter = 0
For Each mnu In mnus
lnk = mnu.Attribute("href")
我对网络抓取相当陌生,我在 VBA/Excel 中使用 Chrome 开始使用 Selenium。我的目标元素是菜单项。
在某些网站上我可以找到这些元素,但我找不到它们 "href"。这里是destination website。我想要页面右侧菜单项的"href"。
这是我试过的:
' geting the menus, working well:
Set mnus = bot1.FindElementsByClass("topmenu")
MenuCounter = 0
For Each mnu In mnus
'getting the href, fails
lnk = mnu.Attribute("href")
我也尝试了其他一些方法,但没有成功。
这是检查的屏幕截图:
请注意,我不仅需要这个特定元素的 href(其 href 是 "art")。我还想要其他等效菜单项的 href(第一项除外)。
href 值在锚标记内 不是 li element.You 需要在 css 选择器之后定位锚 tag.Use。
Set mnus = bot1.FindElementsByCssSelector("li.topmenu >a[href]")
MenuCounter = 0
For Each mnu In mnus
lnk = mnu.Attribute("href")
或者要获取所有菜单 link 试试这个。
获取所有菜单link
Set mnus = bot1.FindElementsByCssSelector("ul.topmenu a[href]")
MenuCounter = 0
For Each mnu In mnus
lnk = mnu.Attribute("href")