Is it possible to use the Selenium library, webdriver.Chrome in MATLAB?

38 visualizaciones (últimos 30 días)
Lucas Lima
Lucas Lima el 3 de Mayo de 2018
Respondida: Daniel el 24 de Mzo. de 2023
I have a code in python and am passing the application to MATLAB. Only the code is using the webdriver library to grab the information from the site.
# Open site
browser = webdriver.Chrome ()
browser.get ('http://icgem.gfz-potsdam.de/ICGEM/Service.html')
        
# Model Directory
model_dir = Select (browser.find_element_by_id ('model_directory'))
model_dir.select_by_visible_text (dire)
How can I solve it?
  1 comentario
Amit Madahar
Amit Madahar el 23 de Ag. de 2019
Hi Lucas,
Did you manage to use Selium libraries in Matlab to run headless chrome? I am trying to resolve a similar issue.
Thanks
Amit

Iniciar sesión para comentar.

Respuestas (1)

Daniel
Daniel el 24 de Mzo. de 2023
When I wanted to do something like this recently, I was able to run the Python file containing the Selenium calls from MATLAB. Relevant commands:
pyrun runs a single command in the Python environment.
pyrunfile executes a .py file.
Both of these commands can pass outputs back to MATLAB.
To point MATLAB to the correct Python interpreter, you use pyenv.
Here are the commands I used to import temperature data from a website for analysis:
The first time I used Python, I ran
pyenv(Version="C:\Users\<username>\AppData\Local\Programs\Python\Python310\python.exe")
to link MATLAB to my Python 3.10 installation. That got stored in MATLAB's settings, so I haven't needed to run that since.
To pull weather, I run
[daysText, tempsText] = pyrunfile("crawlWeather.py",["daysText","tempsText"],year=year,month=month);
"crawlWeather.py", obviously, is the name of the Python script, which assumes that "year" and "month" exist, and pulls weather data accordingly.
"daysText" and "tempsText" are the names of the variables which the script generates, and which I want to import into MATLAB for further analysis. So the argument ["daysText","tempsText"] asks pyrunfile to return those two variables, and I collect them as the return arguments.
"year=year" sets the Python variable "year" to the contents of the MATLAB variable "year".

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by