Amit Shah
Amit Shah

Reputation: 65

Extracting data from website using Selenuim VBA

Finding difficulty in extracting the IEC code from this website: http://eodc.online/

Sample Numbers to search for :

  1. 0530154706
  2. 0530154706
  3. 0330005903

I have series of numbers which will go to Search bar and then click on Submit.

Image 1

Option Explicit

Public Sub EODCsite()

Dim bot As WebDriver
Dim count As Long

Set bot = New WebDriver
bot.Start "chrome"
count = 1
While (Len(Range("A" & count)) > 0)

bot.Get "http://eodc.online/"

bot.FindElementById("authorise_no").SendKeys Range("A" & count)
bot.FindElementById("auth_details").Click

Range("B" & count) = bot.FindElementByXPath("//span[@id='IEC_code']").Text

count = count + 1

Wend
bot.Quit

End Sub

 '     "command": "doubleClick",
  '    "target": "id=IEC_code",
   '   "targets": [
    '    ["id=IEC_code", "id"],
     '   ["css=#IEC_code", "css:finder"],
      '  ["xpath=//span[@id='IEC_code']", "xpath:attributes"],
       ' ["xpath=//div[@id='showLicense']/div/span[6]", "xpath:idRelative"],
 '       ["xpath=//span[6]", "xpath:position"],
  '      ["xpath=//span[contains(.,'0591045869')]", "xpath:innerText"]

The comments in the end is the Java Code I got from Selenium IDE Chrome extension after running on one example.

I can only fill the first cell.

I have less experience in Span Id and Css Selectors (if required).

Upvotes: 0

Views: 174

Answers (1)

QHarr
QHarr

Reputation: 84475

This is pseudo code steps. Essentially, you need 1) to loop over codes 2) submit a code into a cleared input box 3) Wait for results to render. (Code is not intended to be copy pasted and is not tested but is an approximation to what I would write)

for code in codes: ' this is your loop over the cells
    bot.FindElementById("authorise_no").sendKeys code  'enter
    bot.FindElementById("auth_details").click 'submit

    Do
        DoEvents
    Loop While document.querySelector("#showLicense").getAttribute("style") = "display: none;" 'loop until style attribute becomes empty for showLicence node 

    If document.querySelector("#showLicense").getAttribute("style") = vbNullString Then

        Application.Wait Now + Timeserial(0,0,1) ' small pause for results to render
        Debug.Print bot.FindElementById("IEC_code").text 'do something with result
    End If    
    bot.execute_script("document.querySelector('#authorise_no').value= '';") 'clear value ready for next value

Upvotes: 1

Related Questions