twitter(推特)自动评论

推特能爬的都差不多了,这两天写了一个自动留言的功能

主要就是用selenium,bs,懂得都懂!

好像也没其他办法了,代码比较机械简单,功能大概就酱吧

Twitter自动留言34 播放 · 0 赞同视频​

比较核心的代码在下面,有需要的朋友可以参考(当然还有一些,比如定位第一条推特啊,配置proxy一类的就自己琢磨吧!)

from getpass import getpass import json from selenium import webdriver import time import re import random from bs4 import BeautifulSoup from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains import requests from fake_useragent import UserAgent #第一步,储存登录,储存cookie def login_twitter(username, password): driver = webdriver.Chrome() driver.get("") username_field = driver.find_element_by_name("session[username_or_email]") password_field = driver.find_element_by_name("session[password]") username_field.send_keys(username) driver.implicitly_wait(1) password_field.send_keys(password) submit = driver.find_element_by_xpath("/html/body/div/div[2]/main/div/div/div[1]/form/div/div[3]/div/div") submit.click() f = open(/home/solin/tw.txt)#这里直接是网址了 a=f.readlines() for name in a: try: username=name.strip(\n) driver.get(username) time.sleep(5) chat=driver.find_element_by_css_selector("[aria-label=Reply]") time.sleep(1) chat.click() send1=driver.find_element_by_xpath(/html/body/div/div/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div/div/div/div[1]/div/div/div/div[2]/div/div/div/div) send1.send_keys(Dear Sir/Madam. This is Delica Medical who is working on robotic-TCD for neuro ICU cerebral automatic monitoring and multimodal solutions. We have reference sites across Europe and USA.) time.sleep(1) sb1=driver.find_element_by_xpath(/html/body/div/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div) sb1.click() time.sleep(2) username = name.strip(\n) driver.get(username) time.sleep(5) chat = driver.find_element_by_css_selector("[aria-label=Reply]") time.sleep(1) chat.click() send2 = driver.find_element_by_xpath( /html/body/div/div/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div/div/div/div[1]/div/div/div/div[2]/div/div/div/div) send2.send_keys(May we have the honor to send you the device publication and introduction per mail for further cooperation discussion? Our contact is [email protected]; What is your hospital/institution and email contact?) sb1 = driver.find_element_by_xpath( /html/body/div/div/div/div[1]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[3]/div/div/div/div[2]/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div) sb1.click() interval=random.randint(225, 300) time.sleep(interval) except: pass

谢谢您的观看!