鄭重聲明, 本文僅用作學習研究使用,請勿用作商業用途,遵守法律!!!
部署環境有些坑,踩一次就夠了。。。
原項目地址
git clone 原項目以及 識別驗證碼的模型
如果遇到 無法解析的問題 ,則 yum update nss curl
git clone https://github.com/testerSunshine/12306model.git (我個人也有保存網盤)
git clone https://github.com/testerSunshine/12306.git
安裝 requirements.txt
推薦 anaconda 進行包管理, conda create -n py36 然后 配置一下 環境變量 一頓 安裝
/home/ml/anaconda3/bin/pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
可能會少一些 模塊
pip install opencv-python
下載 chrome 以及 chrome driver
1、安裝chrome
用下面的命令安裝最新的 Google Chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
也可以下載到本地再安裝
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install ./google-chrome-stable_current_x86_64.rpm
安裝必要的庫
yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts
還有其他的 谷歌瀏覽器問題
https://www.e-learn.cn/content/qita/2350043
2、安裝 chromedriver
chrome官網 wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
淘寶源(推薦)wget http://npm.taobao.org/mirrors/chromedriver/2.41/chromedriver_linux64.zip
將下載的文件解壓,放在如下位置
unzip chromedriver_linux64.zip
/usr/bin/chromedriver
給予執行權限
chmod +x /usr/bin/chromedriver
設置 chrome driver 參數信息
grep -r 'webdriver'
vim config/getCookie.py
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless')
from selenium import webdriver
cookies = []
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('headless')
driver = webdriver.Chrome(chrome_options=options, executable_path=TickerConfig.CHROME_PATH)
driver.get("https://www.12306.cn/index/index.html")
其中
“–no-sandbox”參數是讓Chrome在root權限下跑
“–headless”參數是不用打開圖形界面
可以額外加這些參數獲得更好體驗
其中
“–no-sandbox”參數是讓Chrome在root權限下跑
“–headless”參數是不用打開圖形界面
可以額外加這些參數獲得更好體驗
options.add_argument('blink-settings=imagesEnabled=false')
options.add_argument('--disable-gpu')
同步時間 並 修改時區
sudo ntpdate -u 210.72.145.44
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
放置 預測模型文件
cp 12306models/xxx.h5 12306/