首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何自动化团队协作备份下载

如何自动化团队协作备份下载
EN

Stack Overflow用户
提问于 2015-04-19 01:56:04
回答 1查看 238关注 0票数 0

我正在尝试自动下载由团队合作创建的备份文件。它的工作方式是登录到一个页面,该页面用src="https://tw-backup.teamwork.com/ext.cfm?backupaction=downloadLatestMySQLBackup"加载动态生成的iframe。

我试过从iframe那里得到实际的链接,但我还没有让它起作用。但是,如果我在浏览器中输入该链接,那么我使用的截尾链接似乎是有效的。所以我只是想直接打开它。

不幸的是,它似乎只是挂起来了。

编辑

幻影--版本= 1.9.8;

获取此错误:

代码语言:javascript
复制
[debug] [phantom] url changed to "https://tw-backup.teamwork.com/ext.cfm?backupa
ction=downloadLatestMySQLBackup"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Done 8 steps in 3427ms
finished
Unsafe JavaScript attempt to access frame with URL about:blank from frame with U
RL file:///c:/Users/Brad/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap
.js. Domains, protocols and ports must match.

那么,问题是,我试图访问一个不同的子域,而不是从哪里开始?

如果你对这个问题感兴趣,你可以得到团队合作的免费试用。和BTW,我们正在很好地利用它来进行项目管理。

代码语言:javascript
复制
var casper = require('casper').create();

casper.start('https://myco.teamwork.com/', function () {

    console.log("start");

    this.waitForSelector("input[name='userLogin']",
        function success() {
            this.sendKeys("input[name='userLogin']", "me@myco.org");
        },
        function fail() {
            test.assertExists("input[name='userLogin']");
        });
    this.waitForSelector("input[name='password']",
        function success() {
            this.sendKeys("input[name='password']", "somePassword");
            console.log("login successful");
        },
        function fail() {
            test.assertExists("input[name='password']");
            console.log("login failed");
        });

    this.thenOpen('https://tw-backup.teamwork.com/ext.cfm?backupaction=downloadLatestMySQLBackup');   

});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-01 15:41:19

我最终通过使用Selenium并使用Chrome驱动程序实现了这一点;Firefox驱动程序将无法工作,因为它会弹出一个保存对话框。

不幸的是,我没有得到这份工作的无头。我希望HtmlUnitDriver能起作用。这仍然是可能的,但就我的目的而言,打开浏览器实际上是可以的。

注意,您需要安装Chrome http://code.google.com/p/selenium/wiki/ChromeDriver。在MAC上,你只要把它放到/usr/bin里就行了。在Windows上,使用.jar和chromedriver.ext创建一个文件夹。然后用以下方式执行:

代码语言:javascript
复制
C:\Program Files\teamworkbackup>java -Dwebdriver.chrome.driver=:"C:\Program files\teamworkdbackup\chromedriver.exe" -jar teamworkdbackup.jar

源代码:

代码语言:javascript
复制
package com.rhoads.teamwork.backup;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;


public class TeamworkBackup {

    public static void main(String[] args) throws Exception {

        WebDriver driver;

        String baseUrl;

        driver = new ChromeDriver();

        baseUrl = "https://myco.teamwork.com/index.cfm";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get(baseUrl + "/");
        Thread.sleep(4000);
        driver.findElement(By.id("password")).clear();
        driver.findElement(By.id("password")).sendKeys("superstrong");
        driver.findElement(By.id("userLogin")).clear();
        driver.findElement(By.id("userLogin")).sendKeys("someguy@example.com");
        driver.findElement(By.id("ordLoginSubmitBtn")).click();
        Thread.sleep(4000);
        driver.get("https://myco.teamwork.com/settings?display=export");
        Thread.sleep(4000);
        driver.switchTo().frame("backupFrame");
        Thread.sleep(4000);
        driver.findElement(By.linkText("Download")).click();
        Thread.sleep(4000);
        driver.quit();


    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29724951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档