extract data from web to inside sheet without open website &refersh

tubrak

Board Regular
Joined
May 30, 2021
Messages
218
Office Version
  1. 2019
Platform
  1. Windows
hi experts
I have this website CMA CGM | A world leader in maritime and logisticsshows me my cargo where is location & when arrive and departure . it depends on CONTAINER NO or B\L NO
let's take CONTAINER NO as the pic 1
1.PNG


and when press shipment tracking it will shows the detials as this picture
2.PNG


so what I want based on last picture show in columns A,B,C,D,E,F= DATE, TIME , MOVES,LOCATION,VESSEL,VOYAGE without open website
and I want put the CONTAINER NO or B\L NO into TEXTBOX1 ACTIVE X and I would press F5 to refresh the search inside the sheet
somtimes doesn't show detiales that's because CONTAINER NO or B\L NO is wrong then should show warning message" please make sure the right detiales "
by the way I use browser google chrome .
thanks
 
You can ignore it; but "tomorrow", when you'll run the macro that I didn't yet provide :) you will be told that the driver cannot open Chrome because Chome in the meantime has been updated to version 102. At that time you'll need to update the driver before can start the process.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
thanks for clarification , what about Windows 64 kernel as I posted?
 
Upvote 0
ok I extracted the ChromeDriver for the directory where the selenium program is installed and ask me replace it and I did it and I disable updating the google chrome.
 
Upvote 0
A demo file can be downloaded here:

Having enabled the Selenium environment, we can use the following macro:
Code:
Sub myCaller()
Dim WPage As Object, TBColl As Object
Dim myUrl As String, mElem As Object
Dim I As Long, tbC As Long
'
'Crea Driver:
'    Set WPage = CreateObject("Selenium.EdgeDriver")
    Set WPage = CreateObject("Selenium.CHRomedriver")
'
Sheets("Main").Select
myUrl = Range("B1")
Range("A5").Resize(2000, 30).Clear      'Clear results area
'
WPage.Get myUrl
WPage.Wait 500
On Error Resume Next
    Set myDoc = WPage.FindElementById("track-number")
    Set myTrack = WPage.FindElementById("searchTracking")
    WPage.FindElementById("onetrust-accept-btn-handler").Click
    WPage.Wait 200
On Error GoTo 0
'
If (Not myDoc Is Nothing) And (Not myTrack Is Nothing) Then
    myDoc.SendKeys Sheets("Main").Range("B2")
    WPage.Wait 100
    myTrack.Click
Else
    MsgBox ("Error A, elements not found")
    GoTo SQuit
End If
Sleep 1000
On Error Resume Next
    Set mElem = WPage.FindElementById("gridTrackingDetails")
    Set TBColl = mElem.FindElementsByTag("table")
    tbC = TBColl.Count
    Debug.Print "TBC= " & tbC
    Debug.Print TypeName(mElem), TypeName(TBColl)
On Error GoTo 0
'
Range("A4").Value = "Returned infos:"
Range("B5").Value = "No information returned, TBC=" & tbC
For I = 1 To tbC
    TBColl(I).AsTable.ToExcel Sheets("Main").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Next I
'
SQuit:
WPage.Quit
Set WPage = Nothing
MsgBox "Completed"
End Sub
This assumes that the site Url is in B1 and the element to search in in B2
On the demo sheet a button starts the Sub myCaller

The information will be written in A5 and subsequent rows

Note that I have investigated only what the site returns with elements of the class "CMAU6702837"; if it deals with different types of elements its retuens might be inconsistent
 
Upvote 0
gives compile error sub or unction not defined in this
Sleep
 
Upvote 0
My error... replace that line with
Excel Formula:
WPage.Wait 1000
 
Upvote 0
This is related to Selenium installation.

Check in which directory selenium has been installed and take and publish a screenshot of what is in that directory
 
Upvote 0
this is directory when install it
C:\Users\PC WORLD\AppData\Local\SeleniumBasic
and this the all files
ا1.PNG
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,155
Members
452,615
Latest member
bogeys2birdies

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