[PYTHON] Let's tweet by hitting the terminal while screaming with Selenium! !!

Sample code

tweet.py


#!/usr/bin/env python
# coding=utf-8

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import settings
import time

# Launch browser
driver = webdriver.Chrome()

# Maximize browser
#driver.maximize_window()

# Access site
url = "https://twitter.com/login"
driver.get(url)

# Get title
print(driver.title)

# Input email and password
screen_name = driver.find_element_by_class_name("js-username-field")
password = driver.find_element_by_class_name("js-password-field")
screen_name.send_keys(settings.my_name)
password.send_keys(settings.passwd)

# Submit
password.submit()

time.sleep(1)

# Tweet
tweet = driver.find_element_by_id("tweet-box-home-timeline")
tweet.send_keys("No progress!")
post = driver.find_element_by_css_selector("button.tweet-action")
post.click()

time.sleep(1)

driver.refresh()

settings.py


my_name = "username"
passwd = "password"

Chrome Web Driver

Download and install Selenium's Chrome driver from here! !!

Summary

It's different from the original usage, but I think it's good to get used to playing properly and mastering the original usage (test)! !!

Recommended Posts

Let's tweet by hitting the terminal while screaming with Selenium! !!
Repeat with While. Scripts to Tweet and search from the terminal
I liked the tweet with python. ..
Let's play with the corporate analysis data set "CoARiJ" created by TIS ①
Let's play with the corporate analysis data set "CoARiJ" created by TIS ②
Tweet the weather forecast with a bot
Let's tune the model hyperparameters with scikit-learn!
Let's solve the portfolio with continuous optimization
Let's read the RINEX file with Python ①
Install by specifying the version with pip
[Python] Automatically operate the browser with Selenium
Let's explain the asset allocation by the Black-Litterman model (with an execution example by Python)
Let's create it by applying Protocol Buffer to the API with Serverless Framework.