Forum

Notifications
Clear all

Scrape Data

2 Posts
2 Users
0 Reactions
79 Views
(@ifalu)
Posts: 1
New Member
Topic starter
 

Hello

 

I read your article https://www.myonlinetraininghub.com/web-scraping-filling-forms

And thanks for that, I am trying to do something similar on this site

https://safer.fmcsa.dot.gov/mcs150t/PKG_CT_PUBLIC.PRC_CT_PUBLIC_SEARCH

I am testing by specifying only the state Alabama value = ALUS

 

However it says it can't find the element ID, not sure what I am missing this is my code

Option Explicit

' Written by Philip Treacy
' https://www.myonlinetraininghub.com/web-scraping-filling-forms

Sub Scrape()

Dim Driver As New Selenium.ChromeDriver
Dim count As Long

Sheets("VAT Lookup").Activate

Set Driver = CreateObject("Selenium.ChromeDriver")
count = 1

' Code assumes all VAT numbers in Column A are valid
' No error checking is included here in case they are not
'
' While (Len(Range("A" & count)) > 0)

Driver.Get "https://safer.fmcsa.dot.gov/mcs150t/PKG_CT_PUBLIC.PRC_CT_PUBLIC_SEARCH"
Driver.FindElementById("pv_state_code").SendKeys "ALUS"
' Driver.FindElementById("number").SendKeys Range("A" & count)
Driver.FindElementById("submit").Click

' Uncomment the next line if you need to introduce a delay in the browser
' to allow it to load the results page
'Driver.Wait 1000

Range("B" & count) = Driver.FindElementByXPath("//table[2]/tbody/tr[2]/td[2]").Text

count = count + 1

' Wend

Driver.Quit

End Sub

 
Posted : 28/11/2019 2:19 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Ian,

If you look at the source code for that page you'll find this bit for the State Code

  <select name="pv_state_code" class="form_data_left" id="state" >

The ID of the element is state but your VBA is looking for the ID pv_state_code

Change that and see if it fixes the issue.

Regards

Phil

 
Posted : 01/12/2019 7:43 pm
Share: