# Selenium X Python --- # Outline 1. About Selenium & Python 3. Install Python & Practice 5. Install Selenium & Practice 7. Cask study - Gym Booker --- # About Selenium - Web 自動化測試工具 - 支援各瀏覽器:Chrome、Firefox、Safari - 支援各種語言:Python、Java、Ruby、C#、Perl ---- # About Python - Programming Language - 好用易懂、開源易分享、大量函式庫 - 應用廣泛:大數據、AI、自動化 > https://www.python.org/about/ --- # Install Python 1. Homebrew 2. Python3 3. PiP 4. Jupyter ---- ## Homebrew Steam: Install Game Tools Homebrew: Install Shell Tools PiP: Install Python Packages Tools ![Steam](https://www.pcgamesn.com/wp-content/uploads/legacy/valve_steam_games.png) ---- Open your terminal ``` /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew --version ``` ---- ## Python3 ``` brew install python3 python3 --version ``` ---- ## PiP ``` curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python3 get-pip.py pip3 --version ``` ---- ## Jupyter ``` pip3 install jupyter jupyter --version ``` --- # Python Practice 程式語言:一種語言 單字:關鍵字 文法:if-else、for ---- 建立一個新資料夾存放 Python 程式,並用 command 切換到這個資料夾 ``` jupyter notebook ``` ---- ## Python Practice Print & Variable ``` print('Hello World!') btcBoundary = 10000 print('BTC Boundary: ' + str(btcBoundary)) ``` If-Else ``` nowBtc = 9999 if (nowBtc > btc): print("SongLa") else: print("GoWork") ``` For-Loop ``` for i in range(1, 11): print(i) ``` --- # Install Selenium ``` pip3 install selenium ``` > https://pypi.org/project/selenium/ > https://learngeb-ebook.readbook.tw/intro/selenium.html ---- # Install Chrome WebDriver 根據你的 Chrome 版本下載相對應的 WebDriver 後 複製到剛剛的 Python 資料夾 [Download by Your chrome Version](https://sites.google.com/a/chromium.org/chromedriver/downloads) 或者直接使用 brew 來安裝 ``` brew cask install chromedriver chromedriver --version // Show the version & link location brew cask list chromedriver ``` --- # Selenium Practice Open Chrome ``` from selenium import webdriver browser = webdriver.Chrome() ``` ---- Open Url ``` browser.get('http://www.google.com') ``` ---- Find Element ``` find_element_by_id find_element_by_name find_element_by_xpath find_element_by_link_text find_element_by_partial_link_text find_element_by_tag_name find_element_by_class_name find_element_by_css_selector ``` --- # Case Study # Trouble Shooting Python version for pip installation. ``` python3.7 -m pip install requests python3.7 -m pip install slackclient ``` ---- Disable chrome auto update. ``` defaults write com.google.Keystone.Agent checkInterval 0 ``` --- # Reference https://selenium-python-zh.readthedocs.io/en/latest/index.html
{"metaMigratedAt":"2023-06-14T22:26:08.818Z","metaMigratedFrom":"Content","title":"Selenium X Python","breaks":true,"contributors":"[{\"id\":\"f83f3ca2-78cb-4e65-8ae3-14ec92337aeb\",\"add\":3487,\"del\":829}]"}
    709 views