extract data from web by using selenium & browser google chrome

Alaa mg

Active Member
Joined
May 29, 2021
Messages
375
Office Version
  1. 2019
hello
I search so much in this forum until found this simlir for my thread extract data from web to inside sheet without open website &refersh
but actually i don't have any idea how deal with th codes to link with website to adjusting for my requirements .
the website is Track Shipment | Cargo & Container Tracking | Maersk and when write container MRKU5693621 should be the data in sheet based on cell C2
search.xlsm
ABCDE
1Container number
2MRKU5693621
3
4Container numberFromTo
5MRKU5693621Gautam Budhh NagarNewark
6
7MRKU569362140' Dry
8Estimated arrival dateLast locationHide details
925-May-22Load • Salalah, Oman • 06 May 2022
10
11Gautam Budhh NagarGate out
12Concor, DadriEmpty
134/12/2022 11:00
14
15
16Gate in
174/12/2022 12:00
18Gate out
194/13/2022 17:10
20PipavavGate in
21Pipavav Terminal4/16/2022 3:36
22Load on MAERSK DETROIT / 215W
234/23/2022 0:21
24
25
26SalalahDischarge
27Salalah Terminal4/28/2022 13:29
28Load on MAERSK SENTOSA / 216W
295/6/2022 21:48
30
31
32NewarkDischarge
33Apm Terminal - Berth 88 E4255/25/2022 7:00
34Gate out
355/25/2022 7:00
SHIP

by the way I use google chrome browser & selenium program
any help I truly appreciated .
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The below should give you a good start:
VBA Code:
Sub test2()
    Dim driver As New webdriver
   
    With driver
        .Start "Chrome"
        .Get "https://www.maersk.com/tracking/"
        .FindElementByClass("coi-banner__accept--fixed-margin").Click
        .FindElementById("track-input").SendKeys (Range("C2").Value)
        .FindElementByClass("track__search__button").Click
       
        cNum = .FindElementByClass("search-summary--bol__dd").Text
        frm = .FindElementByClass("search-summary--from__dd").Text
        to_ = .FindElementByClass("search-summary--to__dd").Text
        arrDate = .FindElementByClass("summary__text--date").Text
        LastLoc = .FindElementByClass("summary__text--location").Text
        TranPlan = .FindElementByClass("transport-plan").Text
    End With
    Stop
End Sub
 
Upvote 0
thanks ! but it shows error user defined type not defined in this line
VBA Code:
driver As New webdriver

it seems to need selecting something from reference , but I no know what's exactly.
 
Upvote 0
You will need to add a reference to the Slenium library in the VBE, i assumed you had done this already as the question was about selenium.
 
Upvote 0
you are right I selected and gives mismatch in this line
VBA Code:
.Start "Chrome"
what means,please?
 
Upvote 0
It means that Selenium has failed to connect to the Chrome driver, quite often the chrome driver installed is not the same as the one needed.

Check that you have the correct version of the Chrome driver for your Chrome install, this is part of setting up Selenium.
 
Upvote 0
thanks again . I downloaded the chromedriver ChromeDriver 101.0.4951.41 despite my version ChromeDriver 101.0.4951.67 .I don't find it based on website link on OP
ok it's gone the error, but shows another error out of memory in this line
VBA Code:
.FindElementByClass("coi-banner__accept--fixed-margin").Click
 
Upvote 0
That line is clicking the accept all to cookies, if you don't get the cookies message then you can try removing that line.

Try as below:
VBA Code:
Sub test2()
    Dim driver As New webdriver
   
    With driver
        .Start "Chrome"
        .Get "https://www.maersk.com/tracking/"
        '.FindElementByClass("coi-banner__accept--fixed-margin").Click
        .FindElementById("track-input").SendKeys (Range("C2").Value)
        .FindElementByClass("track__search__button").Click
       
        cNum = .FindElementByClass("search-summary--bol__dd").Text
        frm = .FindElementByClass("search-summary--from__dd").Text
        to_ = .FindElementByClass("search-summary--to__dd").Text
        arrDate = .FindElementByClass("summary__text--date").Text
        LastLoc = .FindElementByClass("summary__text--location").Text
        TranPlan = .FindElementByClass("transport-plan").Text
    End With
    Stop
End Sub
 
Upvote 0
it stops in this line
VBA Code:
        .FindElementByClass("track__search__button").Click
and shows error as in picture after shows the picture in website .
2.PNG

1.PNG
 
Upvote 0
You are going to have to try some different things to get those to work, they are working on my end.
Maybe inspect the items that are on the webpage and look to see if the references are the same as mine for the buttons and items etc...

This line:
VBA Code:
.FindElementByClass("coi-banner__accept--fixed-margin").Click
Is supposed to be clicking the 'ALLOW ALL' button

Right click the 'ALLOW ALL' button and inspect it - it will show you the code to that button and the class names assosiated with it.
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,537
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top