【问题标题】:PhantomJS: Download File from Website with Cloudflare ProtectionPhantomJS:使用 Cloudflare 保护从网站下载文件
【发布时间】:2019-03-09 18:44:51
【问题描述】:

我有这个代码并想下载一个文件。解析受保护站点的源代码工作正常,但文件下载不起作用。也许任何人都可以告诉我错误在哪里?

"use strict";
var page = require('webpage').create(),
    system = require('system'),
    address, delay;

 var fs = require('fs');

if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: delay.js URL delay');
    phantom.exit(1);
} else {
    address = system.args[1];
    delay = system.args[2];
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit(1);
        } else {
            window.setTimeout(function () {
                var content = page.content;
                fs.write(address);
                console.log(content);
                phantom.exit();
            }, delay);
        }
    });
}

我是这样执行的:

phantomjs delay.js https://my.url/file.txt 10000

【问题讨论】:

    标签: bash debian phantomjs casperjs


    【解决方案1】:

    好的,我解决了。之前使用 Python 并安装了“cfscrape”。

    import cfscrape
    import sys
    
    scraper = cfscrape.create_scraper()
    
    url = (sys.argv[1])
    cfurl = scraper.get(url).content
    name = url.split('/')[-1]
    
    with open(name, 'wb') as f:
        f.write(cfurl)
    

    【讨论】:

      猜你喜欢
      • 2016-08-25
      • 1970-01-01
      • 2014-03-29
      • 2022-01-20
      • 1970-01-01
      • 2022-01-07
      • 2022-01-06
      相关资源
      最近更新 更多