I'm trying to extract information based on keywords from a website, which is in tabular format. Example here for keywords and sample website is
apple
LG
Samsung
Nokia
Website = www.wikipedia.com
I have kept the keywords in Sheet 1 and the table to be extracted in Sheet 2. I have an issue with going to next line as the table dimension is not same for all. I have attached a screenshot too.
This is my code so far, this is sample data only, i have huge keywords to be searched for in my actual work.
Sub tableextract()
Dim bot As WebDriver
Set bot = New WebDriver
bot.Start "Chrome"
bot.Get "https://www.wikipedia.org/"
r = 1
While (Len(Range("A" & r)) > 0)
bot.FindElementById("searchInput").SendKeys Range("A" & r)
bot.FindElementByXPath("//i[@class='sprite svg-search-icon']").Click
Dim tbl As Selenium.TableElement
Set tbl = bot.FindElementByXPath("//table[@class='infobox biota']").AsTable
ThisWorkbook.Sheets("Sheet2").Range("A1").CurrentRegion.Clear 'THIS IS OPTIONAL
tbl.ToExcel ThisWorkbook.Sheets("Sheet2").Range("A1")
Dim LastRow As Long
On Error Resume Next
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
'MsgBox "Last Row: " & LastRow
Range(LastRow).Offset(1, 0).Select
r = r + 1
Wend
End Sub


//table[@class='infobox biota