-
Notifications
You must be signed in to change notification settings - Fork 4
/
Banned Twitter.py
87 lines (46 loc) · 3.52 KB
/
Banned Twitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
##################################### -PLS READ- ################################################################################################
'''
The code you see below is from my article "I Got Banned From Every Social Media App On Purpose".
The code will login into my Twitter account, navigate Twitter until it finds a trending hashtag.
The code will then keep tweeting until the account gets suspended or banned.
If you want to learn the code below and how to do cool projects like this one for yourself,
you can take my course in Web Scraping where by the end, you will understand what every line
below does.
Here's the link to it: https://www.udemy.com/course/web-scraping-in-python-with-beautifulsoup-and-selenium/?referralCode=939EB64B8E029FCBBDEB
The course is only $15, if you go to the link and it says anything above $100, that's just Udemy's
business model, just wait like 2 days and that price will reduce to around $10-$15.
'''
##################################### -Importing Necessary Libraries- ################################################################################################
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from bs4 import BeautifulSoup
import time
##################################### -Getting banned from Twitter- ################################################################################################
#Opens up a browser and goes to twitter login page
driver = webdriver.Chrome(
'C:/Web Scraping course/chromedriver.exe')
driver.get('https://twitter.com/login')
time.sleep(2)
#inputs an email and password for the login details
login = driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/div[2]/form/div/div[1]/label/div/div[2]/div/input')
login.send_keys('#########')
password = driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/div[2]/form/div/div[2]/label/div/div[2]/div/input')
password.send_keys('########')
password.send_keys(Keys.ENTER)
#This code will go to a trending topic and keep posting "I LOVE WATERMELON SUGAR"
for i in range(100,200):
driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div[1]/div/a/div[2]/div/div').click()
text = driver.find_element_by_xpath('//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[3]/div/div/div/div[1]/div/div/div/div/div[2]/div[1]/div/div/div/div/div/div/div/div/div/div[1]/div/div/div/div/div')
text.send_keys(' I LOVE WATERMELON SUGAR!!!' +str(i)+'')
driver.find_element_by_xpath('//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[3]/div/div/div/div[1]/div/div/div/div/div[2]/div[4]/div/div/div[2]/div[4]/div').click()
#This code follows a bunch of people
for i in range(1, 100):
try:
follow = driver.find_element_by_xpath('//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[2]/div/div/section/div/div/div['+str(i)+']/div/div/div/div[2]/div/div[2]').text
if follow == 'Follow':
driver.find_element_by_xpath('//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div[2]/div/div/section/div/div/div['+str(i)+']/div/div/div/div[2]/div/div[2]').click()
except:
pass