我正在整理一个词汇表和一个宏,以便从vocabulary.com中提取信息。搜索没有按钮,所以我必须使用Enter键,但Keys.Enter不起作用。
宏仍然有效,因为您不必按enter键即可显示站点的定义页面,当您在搜索字段中键入内容时,将弹出最顶部的自动完成结果的定义页面。
问题是,并不是在每种情况下都是最推荐的结果,这就是我正在寻找的单词。我需要让回车击键工作,这个宏是100%有用的。
Sub VocabularyWebScraper()
'Application.ScreenUpdating = False
Dim Driver As New Selenium.ChromeDriver
Dim Keys As Selenium.Keys
Dim count As Long
Sheets("Vocabulary.com Scraping").Activate
Set Driver = CreateObject("Selenium.ChromeDriver")
Set Keys = CreateObject("Selenium.Keys")
count = 1
While (Len(Range("A" & count)) > 0)
Driver.Get "https://www.vocabulary.com/dictionary/"
Driver.FindElementById("search").SendKeys Range("A" & count) + Keys.Enter
Driver.Wait 1000
On Error Resume Next
Range("B" & count) = Driver.FindElementByClass("short").Text
Range("C" & count) = Driver.FindElementByClass("long").Text
count = count + 1
Wend
Driver.Quit
'Application.ScreenUpdating = True
End Sub发布于 2020-06-24 12:02:01
我没能让Enter键起作用,但以防其他人想从Vocabularly.com中提取定义,这里是起作用的。我最终只是点击了我正在寻找的特定单词的按钮。工作得很完美。
Sub VocabularyWebScraper()
Application.ScreenUpdating = False
Dim Driver As New Selenium.ChromeDriver
Dim count As Long
Dim word As String
Sheets("Vocab Web Scraping").Activate
Set Driver = CreateObject("Selenium.ChromeDriver")
count = 1
While (Len(Range("A" & count)) > 0)
word = Range("A" & count)
Driver.Get "https://www.vocabulary.com/dictionary/"
Driver.FindElementById("search").SendKeys word
Driver.Wait 1000
Driver.FindElementByCss("li[word='" + word + "']").Click
Driver.Wait 2000
On Error Resume Next
Range("B" & count) = Driver.FindElementByClass("short").Text
Range("C" & count) = Driver.FindElementByClass("long").Text
count = count + 1
Wend
Driver.Quit
Application.ScreenUpdating = True结束子对象
https://stackoverflow.com/questions/62525980
复制相似问题