Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C语言在AWS Lambda中使用硒铬驱动程序#_C#_Selenium Webdriver_Aws Lambda_Selenium Chromedriver - Fatal编程技术网

C# 使用C语言在AWS Lambda中使用硒铬驱动程序#

C# 使用C语言在AWS Lambda中使用硒铬驱动程序#,c#,selenium-webdriver,aws-lambda,selenium-chromedriver,C#,Selenium Webdriver,Aws Lambda,Selenium Chromedriver,我希望在AWS Lambda函数中使用Selenium Chromedriver,使用C#,但我运气不太好。。。我得到的最初错误是“chromedriver.exe在/tmp/中不存在”。使用Webdrivermanager使我克服了此错误,但现在我在“拒绝访问路径'/tmp/'的权限”方面遇到问题 我已经用谷歌搜索了我的手指,并尝试了多种方法让它工作。我打赌这是我错过的小东西 任何帮助都将不胜感激 using System.Collections.Generic; using Amazon.L

我希望在AWS Lambda函数中使用Selenium Chromedriver,使用C#,但我运气不太好。。。我得到的最初错误是“chromedriver.exe在/tmp/中不存在”。使用Webdrivermanager使我克服了此错误,但现在我在“拒绝访问路径'/tmp/'的权限”方面遇到问题

我已经用谷歌搜索了我的手指,并尝试了多种方法让它工作。我打赌这是我错过的小东西

任何帮助都将不胜感激

using System.Collections.Generic;
using Amazon.Lambda.Core;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using WebDriverManager; 

public class Function
{
    public void FunctionHandler(string input, ILambdaContext context)
    {
        var driver = GetDriver();
        driver.Navigate().GoToUrl(input);
        driver.Quit();
    }

    public IWebDriver GetDriver()
    {
        new DriverManager().SetUpDriver(
            "http://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_win32.zip", 
            "/tmp/", 
            "chromedriver.exe"
        );

        ChromeOptions options = new ChromeOptions();
        options.AddArguments(new List<string>() {
            "--no-sandbox",
            "--headless",
            "--disable-gpu",
            "--homedir=/tmp"
        });
        return new ChromeDriver("/tmp/", options);
    }
}
使用System.Collections.Generic;
使用Amazon.Lambda.Core;
使用OpenQA.Selenium;
使用OpenQA.Selenium.Chrome;
使用WebDriverManager;
公共类函数
{
public void FunctionHandler(字符串输入,ILambdaContext上下文)
{
var-driver=GetDriver();
driver.Navigate().gotour(输入);
driver.Quit();
}
公共IWebDriver GetDriver()
{
新建DriverManager().SetUpDriver(
"http://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_win32.zip", 
“/tmp/”,
“chromedriver.exe”
);
ChromeOptions选项=新的ChromeOptions();
options.AddArguments(新列表(){
“--没有沙箱”,
“--无头”,
“--禁用gpu”,
“--homedir=/tmp”
});
返回新的ChromeDriver(“/tmp/”,选项);
}
}
查看

操作系统-

AMI–amzn-AMI-hvm-2017.03.1.20170812-x86_64-gp2

Linux内核–4.14.77-70.59.amzn1.x86_64

所以我认为你应该用,来代替这一行:

http://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_win32.zip
关于这一点:

https://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_linux64.zip
也许只需
chromedriver


如果你打算投资于基于云的web浏览器自动化,那么使用像或

@Dmitiri这样的专门服务可能会更容易。谢谢你。。。它确实使我克服了这个问题,所以它是正确的。但是,我现在在尝试访问chrome驱动程序时遇到权限错误。此时“返回新的ChromeDriver(“/tmp/”,选项);”@米切尔斯通你好。你是不是碰巧弄到了什么?谢谢:)@ZachOverflow Dmitri是对的,Lambda函数的后端是基于Linux的,所以你需要Linux版本的驱动程序。我们最终没有使用Lambda,驱动程序太大,无法与任何其他库一起上载,因此每次执行Lambda时都必须下载它,这不合适。@MitchellStone感谢大家的帮助。我将尝试破解Lambda,看看它是否可行,但目前我希望在一个容器服务中运行我们的自动化测试——我喜欢使用Fargate的Amazon ECS。我希望我能够通过编程来加速容器等