Last active
June 22, 2020 09:00
-
-
Save Davidaredding/2839b17337986465df2902d74408ae7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using PuppeteerSharp; | |
using System.Collections.Generic; | |
namespace netDemo | |
{ | |
public class Program | |
{ | |
const string Username = "USERNAME"; | |
const string Password = "PASSWORD"; | |
static async Task Main(string[] args) | |
{ | |
Console.WriteLine("Downloading Chrome"); | |
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); | |
Console.WriteLine("Chrome is Current"); | |
var b = await Puppeteer.LaunchAsync(new LaunchOptions{ | |
Headless = false, | |
Args = new[]{"--no-sandbox --disable-notifications"} | |
}); | |
var p = await b.NewPageAsync(); | |
await p.Client.SendAsync("Emulation.clearDeviceMetricsOverride"); | |
await p.GoToAsync("Https://www.reddit.com/login"); | |
await p.WaitForSelectorAsync("fieldset.login"); | |
await p.ClickAsync("fieldset.login"); | |
await p.FocusAsync("fieldset.login :first-child"); | |
await p.Keyboard.TypeAsync(Username,new PuppeteerSharp.Input.TypeOptions{Delay=100}); | |
await p.FocusAsync("fieldset.password :first-child"); | |
await p.Keyboard.TypeAsync(Password,new PuppeteerSharp.Input.TypeOptions{Delay=100}); | |
await p.ClickAsync("button[type=\"submit\""); | |
await p.WaitForNavigationAsync(); | |
await p.GoToAsync("Https://www.reddit.com/r/pics"); | |
await p.WaitForSelectorAsync("HEAD"); | |
Console.WriteLine("Preparing to scroll"); | |
Func<Task> scroll = null; | |
scroll = new Func<Task>(async()=>{ | |
Console.WriteLine("Scrolling"); | |
await p.EvaluateExpressionAsync("window.scrollBy({top:10,behavior:'smooth'})"); | |
Thread.Sleep(100); | |
await scroll(); | |
}); | |
await scroll(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment