C# Puppeteer数据爬取
Startup配置 :
var execPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory +"\\chrome-win\\chrome.exe");
var launchOptions = new LaunchOptions
{
Headless = true,
ExecutablePath = execPath,
IgnoreHTTPSErrors = true,
LogProcess = true,
Args = new string[] {
"--no-sandbox",
"--disable-infobars",
"--disable-setuid-sandbox",
"--ignore-ICertificatePolicy-errors",
"--disable-features=AudioServiceOutOfProcess" }
};
context.Services.AddSingleton(launchOptions);
Puppeteer应用类:
using PuppeteerSharp;
private readonly LaunchOptions launchOptions;
Puppeteer.LaunchAsync(launchOptions)
问题描述
本地调试运行正常,部署线上环境报错!
Puppeteer.LaunchAsync(launchOptions) 报错:
Timed out after 30000 ms while trying to connect to Base!
Puppeteer.LaunchAsync(launchOptions)
原因分析:
本地发布时的谷歌浏览器版本与线上不同
解决方案:
将发布环境的谷歌浏览器版本与本地发布时的谷歌浏览器版本对应即可。