コード例 #1
0
ファイル: Program.cs プロジェクト: Viir/bots-test-github
    static async System.Threading.Tasks.Task StartWebBrowser()
    {
        var browserRevision = PuppeteerSharp.BrowserFetcher.DefaultChromiumRevision;

        var browserFetcher = new PuppeteerSharp.BrowserFetcher(new PuppeteerSharp.BrowserFetcherOptions
        {
            Path = BrowserDownloadDirPath()
        });

        await browserFetcher.DownloadAsync(browserRevision);

        browser = await PuppeteerSharp.Puppeteer.LaunchAsync(new PuppeteerSharp.LaunchOptions
        {
            Headless        = false,
            UserDataDir     = UserDataDirPath("default"),
            DefaultViewport = null,
            ExecutablePath  = browserFetcher.RevisionInfo(browserRevision).ExecutablePath,
        });

        browserPage = (await browser.PagesAsync()).FirstOrDefault() ?? await browser.NewPageAsync();

        await browserPage.ExposeFunctionAsync("____callback____", (string returnValue) =>
        {
            callbackFromBrowserDelegate?.Invoke(returnValue);
            return(0);
        });
    }
コード例 #2
0
        public static async Task <bool> LoginToTiqa(PuppeteerSharp.Browser browser)
        {
            try
            {
                var pages = await browser.PagesAsync();

                var page = pages[0];
                await page.GoToAsync(AppConfig.tiqaUrl);

                var un = await page.WaitForSelectorAsync(AppConfig.unFld);

                var pw = await page.WaitForSelectorAsync(AppConfig.pwFld);

                var lgn = await page.WaitForSelectorAsync(AppConfig.lgnBtn);

                await un.TypeAsync(AppConfig.un);

                await pw.TypeAsync(AppConfig.pw);

                await lgn.ClickAsync();

                await page.WaitForNavigationAsync();

                var cks = await page.GetCookiesAsync();

                AppConfig.cks    = cks.ToList();//.Where(c => c.Domain == new Uri(page.Url).Host).ToList();
                AppConfig.sessId = AppConfig.cks.Where(c => c.Name == AppConfig.sessIdName).FirstOrDefault().Value;
                AppConfig.WriteOut($">> session id for crawl set to {AppConfig.sessId}");
                AppConfig.crawlStartUri = page.Url;
                return(true);
            }
            catch (NavigationException ex)
            {
                AppConfig.ErrHand(ex, $"XX failed to navigate to url");
                return(false);
            }
            catch (Exception ex)
            {
                AppConfig.ErrHand(ex);
                return(false);
            }
        }