pip install selenium
安装chrome driver(参考https://blog.csdn.net/zxy987872674/article/details/53082896)
```
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get("https://twitter.com")
loginBtn = (By.XPATH,'//*[@id="doc"]/div/div[1]/div[1]/div[2]/div[2]/div/a[2]')
driver.find_element(*loginBtn).click()
time.sleep(3)
driver.implicitly_wait(3)
phone_input = (By.XPATH,'//*[@id="page-container"]/div/div[1]/form/fieldset/div[1]/input')
//请替换用户名密码
driver.find_element(*phone_input).send_keys('name')
pwd_input = (By.XPATH,'//*[@id="page-container"]/div/div[1]/form/fieldset/div[2]/input')
driver.find_element(*pwd_input).send_keys('pwd')
loginBtn2 = (By.XPATH,'//*[@id="page-container"]/div/div[1]/form/div[2]/button')
driver.find_element(*loginBtn2).click()
time.sleep(2)
driver.implicitly_wait(2)
happenning = (By.XPATH,'//*[@id="tweet-box-home-timeline"]')
driver.find_element(*happenning).click()
time.sleep(1)
driver.implicitly_wait(1)
driver.find_element(*happenning).send_keys('for test')
time.sleep(1)
driver.implicitly_wait(1)
tweet = (By.XPATH,'//*[@id="timeline"]/div[2]/div/form/div[3]/div[2]/button')
driver.find_element(*tweet).click()
```
网友评论