c# - NET Core 上的 Selenium 在 Linux 上的工作方式不同
问题描述
我使用 net core 和 selenium 开发了一个小爬虫,但我注意到我的程序在 windows 上可以正常工作,而在 centos 上却不能。似乎centos上的驱动程序对象具有与windows完全不同的结构。
这是我的测试代码:
class Program
{
static async Task Main(string[] args)
{
IWebDriver driver = SetupTest2();
driver.Navigate().GoToUrl("https://google.com");
await Task.Delay(5000);
Console.WriteLine(driver.PageSource);
}
public static IWebDriver SetupTest2()
{
String driverPath = @"/root";
String driverExecutableFileName = "chromedriver";
ChromeOptions options = new ChromeOptions();
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
ChromeDriverService service = ChromeDriverService.CreateDefaultService(driverPath, driverExecutableFileName);
IWebDriver driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(30));
return driver;
}
}
在 Windows 上它可以正常工作。Console.WriteLine 打印页面的源代码。而是在centos上打印
System.Collections.Generic.Dictionary`2[System.String,System.Object]
我能做些什么来解决这个问题吗?或者我必须切换到与 python 不同的东西?
解决方案
推荐阅读
- ruby - 由于 NoMethod 错误和与我的 .gemspec 文件相关的问题,无法发布我的 Ruby gem
- javascript - 汉可以在单击按钮时增加setTimeout函数中的时间值吗?
- javascript - 无法使用 jquery 在输入字段中获取 Woocommerce 计费电话
- excel - 如果 table_2 任何地方包含来自 table_1 的 X、Y、Z 值,如何检查函数?
- amazon-web-services - Eureka Server 内存,更新阈值为 0,自我保存问题 - AWS
- python - 如何在 Python 中读取应用程序/八位字节流
- php - sql中小数列的四舍五入
- ios - 由已弃用的库引起的 Flutter ios 构建错误
- c# - 试图用来自 JSON 的值填充 C# 中的 Datagridview,但我只得到 1 个单元格填充
- javascript - 使用 mongoose 从 mongodb 获取对象