Facebook - 获取重复的python函数?

时间:2016-05-19 13:45:04

标签: python python-3.x

我希望有人能够指出我正在犯的错误;它可能非常直接! 我想要做的是先前运行一些代码,然后当我到达这一点时,我需要让它保持600秒,然后重新加载下载页面:

try:
    # Clicks OK in Download Requested window
    driver.implicitly_wait(10)
    ClickOkay = driver.find_element_by_css_selector("._42ft._42fu.layerCancel.uiOverlayButton.selected._42g-._42gy")
    ClickOkay.click()
except:
    print("error 2")
   # Wait Time
   # time.sleep(600)  # Allow Facebook to compile the archive

    # Reload Settings page
    GoToURL('https://www.facebook.com/' + 'settings', driver)

    # Goes back through to Download page
    link = driver.find_element_by_link_text('Download a copy')
    link.click()

此时如果存档已完成创建,则按钮从“开始存档”更改为“下载存档”。但是,根据配置文件的大小,编译存档所需的时间会有所不同。所以我正在尝试(使用下面的代码和if和while参数的几次尝试)是为了让它检查按钮是否存在,如果没有返回并等待300秒再重试。一旦按钮出现,它将继续使用其他代码下载。

    try:
        print("Checking if button exists")
        DownloadArchive = driver.find_elements_by_css_selector("._42ft._42fu.selected._42gz._42gy")
        print(DownloadArchive.count())

        if(DownloadArchive.count() > 0):
            print("button exists")
        else:
            print("button does not exist")
        # Button to initiate password entry popup window
        #driver.implicitly_wait(10)
        #while (DownloadArchive = driver.find_element_by_css_selector("._42ft._42fu.selected._42gz._42gy")):
        #    if (DownloadArchive = True):
        #        DownloadArchive.click()
        #        print("wait")
        #    else:time.sleep(300)

先谢谢你,詹姆斯

1 个答案:

答案 0 :(得分:1)

您正在将赋值运算符(=)与等运算符(==)混合。

所以它应该是:

while (DownloadArchive == driver.find_element_by_css_selector("._42ft._42fu.selected._42gz._42gy")):
    if (DownloadArchive == True):

或者只是:

while DownloadArchive == driver.find_element_by_css_selector("._42ft._42fu.selected._42gz._42gy"):

希望它有所帮助!