Is it possible to use the Selenium library, webdriver.Chrome in MATLAB?
42 次查看(过去 30 天)
显示 更早的评论
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
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
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.
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".
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!