第一步:準備
- 在http://npm.taobao.org/mirrors/chromedriver/87.0.4280.88/下載
chrome 驅動chromedriver(經過測驗,需要87.0.4280.88版本) - 建立chrome檔案夾用來存放第一步下載后的chrome(linux版本)
- 建立檔案夾Spider用來存放requirements.txt 和爬蟲檔案test.py
建立requirements(用來安裝python包)
還有test.py(用來測驗)
requirements.txt
requests==2.23.0
lxml==4.5.1
selenium==3.141.0
test.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chromedriver = "/usr/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chromedriver)
driver.get("https://www.baidu.com")
print(driver.title)
driver.quit()
第二步:開始部署
建立一個作業流

在左側點擊New Workflow,之后點擊Skip this and set up a workflow yourself

命名檔案,以.yml后綴結尾
把左側內容刪掉,
填入以下資訊
name: selenium
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: 'Set up Python'
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: 'Install requirements'
run: pip install -r ./Spider/requirements.txt
- name: 'Working'
run: |
sudo cp -p ./chrome/chromedriver /usr/bin/
chmod -R 777 /usr/bin/chromedriver
python ./Spider/test.py
作業流建立好commit提交后,會自動運行此作業流,點擊actions

左側會有一個名為selenium的作業流(剛剛創建的),
點擊右側
點擊view workflow,再點擊bulid

可以看到運行結果了,

這樣就成功了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/244806.html
標籤:其他
上一篇:12月31日寫成13月1日引發重大 Bug,程式員新年就要被“祭天”?
下一篇:菜鳥看前端(vuex)
