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

42 ビュー (過去 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 Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by