Issue with Twitter login and tweets access

69 views
Skip to first unread message

Yann Barraud

unread,
Jun 17, 2020, 6:57:16 AM6/17/20
to Selenium Users
Hi,

I'm scrapping my twitts and having an issue :
  1. I'm getting logged on twitter (OK)
  2. I'm opening a twitt
    1. Getting an error
    2. Refrshing and it's OK

It is kinda weird. What am I doing wrong?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import getpass

username = "XXXXX"
login = getpass.getpass("Twitter login :")
password = getpass.getpass("Twitter password :")
driver = webdriver.Firefox()

def login_twitter(username, password):
    driver.get("https://twitter.com/login")

    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)

    password_field.send_keys(password)

    driver.find_element_by_xpath("//div[@data-testid='LoginForm_Login_Button']").click()

# deleting phase
def delete_twitt(twittid):
    base_url = "https://twitter.com/" + username + "/status/"
    twitt_url = base_url + twittid

    driver.get(twitt_url)
    driver.implicitly_wait(3)
    driver.refresh()
    try:
        driver.find_element_by_xpath("//div[@data-testid='caret']").click()
        del_button = driver.find_element_by_xpath("//*[contains(text(), 'Supprimer')]")
        del_button.click()
        driver.find_element_by_xpath("//div[@data-testid='confirmationSheetConfirm']").click()
    except:
        print(twitt_url)

login_twitter(login, password)
for tweet in json_twitts[300:350]:
    tweet_id = tweet['tweet']['id']
    delete_twitt(tweet_id)

Thanks for support.

Yann

Joe Ward

unread,
Jun 17, 2020, 7:35:02 AM6/17/20
to seleniu...@googlegroups.com
It’s against twitter’s ToS to do this sort of thing. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e5fa6383-e9a4-4fcf-8e82-a27f7dea7bb7o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages