# dnf install google-chrome
=========================================================================================================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
=========================================================================================================================
依存関係のインストール中:
google-chrome-unstable x86_64 87.0.4280.11-1 google-chrome 72 M
# pip install chromedriver-binary==87.0.4280.11-1
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install –user` instead.
Collecting chromedriver-binary==87.0.4280.11-1
Could not find a version that satisfies the requirement chromedriver-binary==87.0.4280.11-1 (from versions: 2.29.1, 2.31.1, 2.33.1, 2.34.0, 2.35.0, 2.35.1, 2.36.0, 2.37.0, 2.38.0, 2.39.0, 2.40.1, 2.41.0, 2.42.0, 2.43.0, 2.44.0, 2.45.0, 2.46.0, 70.0.3538.16.0, 70.0.3538.67.0, 70.0.3538.97.0, 71.0.3578.30.0, 71.0.3578.33.0, 71.0.3578.80.0, 71.0.3578.137.0, 72.0.3626.7.0, 72.0.3626.69.0, 73.0.3683.20.0, 73.0.3683.68.0, 74.0.3729.6.0, 75.0.3770.8.0, 75.0.3770.90.0, 75.0.3770.140.0, 76.0.3809.12.0, 76.0.3809.25.0, 76.0.3809.68.0, 76.0.3809.126.0, 77.0.3865.10.0, 77.0.3865.40.0, 78.0.3904.11.0, 78.0.3904.70.0, 78.0.3904.105.0, 79.0.3945.16.0, 79.0.3945.36.0, 80.0.3987.16.0, 80.0.3987.106.0, 81.0.4044.20.0, 81.0.4044.69.0, 81.0.4044.138.0, 83.0.4103.14.0, 83.0.4103.39.0, 84.0.4147.30.0, 85.0.4183.38.0, 85.0.4183.83.0, 85.0.4183.87.0, 86.0.4240.22.0)
No matching distribution found for chromedriver-binary==87.0.4280.11-1
最も近いバージョンをインストール
# pip install chromedriver-binary==86.0.4240.22.0
Collecting chromedriver-binary==86.0.4240.22.0
Downloading https://files.pythonhosted.org/packages/08/85/4a12e3ea067901e76a68e5a63cd9237b4959a4558a22594fcfcd47ebf648/chromedriver-binary-86.0.4240.22.0.tar.gz
/usr/local/lib/python3.6/site-packages/setuptools/distutils_patch.py:26: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools’ objects directly or at least import Setuptools first.
“Distutils was imported before Setuptools. This usage is discouraged ”
Installing collected packages: chromedriver-binary
Running setup.py install for chromedriver-binary … done
Successfully installed chromedriver-binary-86.0.4240.22.0
python コード
“`
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import chromedriver_binary
# アカウント情報
account = ‘username”
password = ‘password’
# ツイートしたい文字列
text = “テストツイート”
# Twitterログイン実行する処理
def login_twitter():
# ログインページを開く
driver.get(‘https://twitter.com/login/’)
time.sleep(2) # 待ち
# account入力
element_account = driver.find_element_by_name(“session[username_or_email]”)
element_account.send_keys(account)
time.sleep(2) # 待ち
# パスワードを入力する
element_pass = driver.find_element_by_name(“session[password]”)
element_pass.send_keys(password)
time.sleep(3) # 動作止める
# ログインボタンクリック
element_login = driver.find_element_by_xpath(‘//*[@data-testid=”LoginForm_Login_Button”]’)
driver.execute_script(“window.scrollTo(0, document.body.scrollHeight);”)
element_login.click()
time.sleep(3) # 待ち
def send_tweet(text):
element_text = driver.find_element_by_class_name(“notranslate”)
element_text.click()
element_text.send_keys(text)
tweet_button = driver.find_element_by_xpath(‘//*[@data-testid=”tweetButtonInline”]’)
tweet_button.click()
# seleniumを起動
options=Options()
options.add_argument(‘–headless’)
driver=webdriver.Chrome(chrome_options = options)
# ログイン処理
login_twitter()
# ツイートする
send_tweet(text)
time.sleep(10)
# seleniumを終了
driver.close()
driver.quit()
“`