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

조회 수: 15 (최근 30일)
Lucas Lima
Lucas Lima 2018년 5월 3일
답변: Daniel 2023년 3월 24일
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
Amit Madahar
Amit Madahar 2019년 8월 23일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Daniel
Daniel 2023년 3월 24일
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".

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by