簡體   English   中英

用python實現Facebook帳戶下載自動化?

[英]Facebook account download automation with python?

作為我工作職責中的一項常規任務,我經常必須從用戶帳戶中下載完整的Facebook帳戶。 我正在嘗試改善我的工作流程,並在可能的情況下使其自動化。

我曾嘗試在網站上搜索此主題,盡管許多內容涵蓋了登錄部分,但我還沒有找到解決Facebook彈出窗口的問題。 如果我錯了,我深表歉意,請相應地修改帖子。

首先,我決定開始學習python,並在selenium和Chrome Driver的少許幫助下使用它來編寫過程腳本。 我設法編寫了代碼以登錄並導航到正確的頁面,然后單擊初始鏈接“下載副本”。 但是,我很難使腳本找到並單擊彈出窗口中的“開始我的檔案”按鈕。

這是我到目前為止使用的代碼,包括我嘗試在底部注釋掉的幾個替代代碼塊:

import time

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

#Global Variables
target = "john.doe.7"
username = "john@doe.com"
password = "Password"
sleep = 5

#Finds and locates the ChromeDriver
driver = webdriver.Chrome("C:\Python35-32\ChromeDriver\chromedriver.exe")

#Set Chrome Options
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

#Directs browser to webpage
driver.get('http://www.facebook.com');

#code block to log in user
def logmein():
    search_box = driver.find_element_by_name('email')
    search_box.send_keys(username)
    search_box = driver.find_element_by_name('pass')
    search_box.send_keys(password)
    search_box.submit()

#code to go to specific URL
def GoToURL(URL):
    time.sleep(sleep) # Let the user actually see something!
    driver.get(URL);    

logmein()

GoToURL('https://www.facebook.com/'+'settings')

link = driver.find_element_by_link_text('Download a copy')
link.click()

#driver.find_element_by.xpath("//button[contains(., 'Start My Archive')]").click()

#driver.find_element_by_css_selector('button._42ft._42fu.selected._42gz._42gy').click()

#driver.find_element_by_xpath("//*[contains(text(), 'Start My Archive')]").click()

#driver.find_element_by_css_selector('button._42ft._42fu.layerConfirm.uiOverlayButton.selected._42g-._42gy').click()

#from selenium.webdriver.common.action_chains.ActionChains import driver

#buttons = driver.find_elements_by_xpath("//title[contains(text(),'Start My Archive')]")
#actions = ActionChains(self.driver)
#time.sleep(2)
#actions.click(button)
#actions.perform()

只需將其添加到您的代碼中,然后運行即可(如果無法運行)。 始終使用CssSelector。

看起來我用Java在eclipse中運行了以下代碼,但我不了解python,因此如果語法有誤,我深表歉意。 只需嘗試一下,看看。

driver.implicitly_wait(10)
Startmyarchive = driver.find_element_by_css_selector("._42ft._42fu.selected._42gz._42gy")
Startmyarchive.click()

driver.implicitly_wait(10)
Acknowledge = driver.find_element_by_css_selector("._42ft._42fu.layerConfirm.uiOverlayButton.selected._42g-._42gy")
Acknowledge.click()

driver.implicitly_wait(10)
ClickOkay = driver.find_element_by_css_selector("._42ft._42fu.layerCancel.uiOverlayButton.selected._42g-._42gy")
ClickOkay.click()

祝您學習愉快:-)如有任何疑問,請回復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM