Untitled
unknown
plain_text
3 years ago
4.6 kB
2
Indexable
import selenium, time, pickle, random from selenium import webdriver from selenium.webdriver.chrome.options import Options from datetime import date options=Options() options.headless = False prefs = {"profile.default_content_setting_values.notifications" : 2} options.add_experimental_option("prefs",prefs) try: paths = open('path', 'r').read().splitlines() PATH = paths[0] memes = paths[1] except Exception: PATH = input("where is your chrome driver located : ") memes = input('where is this bot located? it should be something like .../fb_posting_bot : ') if memes [len(memes) - 1] == '/' or memes [len(memes) - 1] == '\\' : memes = memes + 'memes.png' else: if '/' in memes: memes = memes + '/memes.png' else: memes = memes + '\\memes.png' if PATH [len(PATH) - 1] == '/' or PATH [len(PATH) - 1] == '\\' : PATH = PATH + 'chromedriver' elif 'chromedriver' not in PATH: if '/' in PATH: PATH = PATH + '/chromedriver' else: PATH = PATH + '\\chromedriver' paths = open('path', 'w').write(PATH + '\n' + memes) acc = input('choose a username\n') + '.pkl' driver = webdriver.Chrome(PATH, chrome_options=options) def login_cookies(driver, acc): ''' Gets driver and a user/file name as arguments Logs in Facebook with cookies.pkl that are saved in your computer's bot folder ''' driver.get('https://www.facebook.com') #LOGIN BY COOKIES try: account = open(acc, 'rb') cookies = pickle.load(account) print('logged in using cookies, welcome back!') for cookie in cookies: driver.add_cookie(cookie) time.sleep(1) account.close() except Exception: login_type(driver, acc) def login_type(driver, acc): #LOGIN ''' Logs in to Facebook with your e-mail and password receives a driver and a username as arguments to save the cookies. ''' email = input('this is only needed for the first time\n what is your email?\n') password = input('what is your password?\n') driver.get('https://mbasic.facebook.com/') time.sleep(5) emailat = driver.find_element_by_id("m_login_email") passwd = driver.find_element_by_xpath("./html/body/div/div/div[2]/div/table/tbody/tr/td/div[2]/div/div[2]/form/ul/li[2]/section/input") login = driver.find_element_by_xpath("./html/body/div/div/div[2]/div/table/tbody/tr/td/div[2]/div/div[2]/form/ul/li[3]/input") emailat.send_keys(email) passwd.send_keys(password) login.click() time.sleep(6) #save_cookies account = open(acc, 'wb') pickle.dump(driver.get_cookies(), account) account.close() def del_ua(k): driver.get('https://mbasic.facebook.com/friends/center/friends/?mff_nav=1') for i in range(1, 11): try: profile = './html/body/div/div/div[2]/div/div[1]/div[2]/div[' + str(i) + ']/table/tbody/tr/td[2]/a' driver.find_element_by_xpath(profile).click() time.sleep(3) driver.find_element_by_xpath('./html/body/div/div/div[2]/div/table/tbody/tr/td/div/section[3]/a').click() time.sleep(3) driver.find_element_by_xpath('./html/body/div/div/div[2]/div/div[1]/div[1]/div[4]/a[1]').click() time.sleep(3) birth = driver.find_element_by_css_selector('#basic-info > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > div:nth-child(1)').text print(birth) for s in birth.split(): if s.isdigit() and int(s)>1000: year = int(s) if year > (date.today().year - 18): time.sleep(2) driver.find_element_by_xpath('./html/body/div/div/div[2]/div/div[1]/div[1]/div[3]/table/tbody/tr/td[2]/a').click() time.sleep(2) driver.find_element_by_xpath('./html/body/div/div/div/div/table/tbody/tr/td/section/ul/li[1]/a').click() time.sleep(2) driver.find_element_by_xpath('./html/body/div/div/div[2]/div[2]/div[1]/form/input[3]').click() except Exception: pass finally: driver.get('https://mbasic.facebook.com/friends/center/friends/?mff_nav=1') for j in range(k): time.sleep(3) driver.find_element_by_xpath('./html/body/div/div/div[2]/div/div[1]/div[3]/a/span').click() login_cookies(driver, acc) k = 0 while True: del_ua(k)
Editor is loading...