本帖最后由 鱼塘是我的 于 2019-11-29 17:26 编辑
打开网页 => hook同时识别验证码 =>输入验证码=>模拟登录
using System;
using System.Threading;
using System.Threading.Tasks;
using PuppeteerSharp;
using Baidu.Aip.Ocr;
using System.Collections.Generic;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
pageInitialized().Wait();
}
static async Task pageInitialized()
{
try
{
string verificationCode;
using (Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions()
{
ExecutablePath = @"C:\Users\Hasee\AppData\Local\Google\Chrome SxS\Application\chrome.exe",
Headless = false,
IgnoreHTTPSErrors = false,
IgnoredDefaultArgs = new string[] { "--enable-automation" },
DefaultViewport = new ViewPortOptions
{
Width = 800,
Height = 800
}
}))
{
using (var page = await browser.NewPageAsync())
{ //Hook
await page.SetRequestInterceptionAsync(true);
page.Request += Page_Request;
page.Response += Page_Response;
await page.GoToAsync("https://passport.jumpw.com/login.jsp");
Console.WriteLine("请输入验证码");
verificationCode = Console.ReadLine().ToString();
Console.WriteLine(verificationCode);
//自动化登录
await page.WaitForSelectorAsync("body > section.login-btn-box > div > div > div > div > div:nth-child(1) > div");
await page.TapAsync("body > section.login-btn-box > div > div > div > div > div:nth-child(1) > div");
await page.WaitForSelectorAsync("#userName");
await page.TypeAsync("#userName", "13868137181");
await page.WaitForSelectorAsync("#browserPwd");
await page.TypeAsync("#browserPwd", "123456");
await page.WaitForSelectorAsync("#VerifyCodeKey");
await page.TypeAsync("#VerifyCodeKey", "verificationCode");
await page.TapAsync("#selfdom > div");
await page.ScreenshotAsync("测试截图.png");
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
private async static void Page_Request(object sender, RequestEventArgs e)
{
await e.Request.ContinueAsync();
}
//验证码识别
private async static void Page_Response(object sender, ResponseCreatedEventArgs e)
{
if (e.Response.Url.Contains("passport.jumpw.com/VerifyCodeServlet?codetype=LOGIN"))
{
Ocr client;
client = new Ocr("MV2wRoxwcj4MMwPhOYSb*****", "xK7f48rt4FhrYO5p7***********");
byte[] buffer = await e.Response.BufferAsync();
var result = client.AccurateBasic(buffer);
var options = new Dictionary<string, object>()
{
{"language_type", "CHN_ENG"},
{"detect_direction", "true"},
{"detect_language", "true"},
{"probability", "true"}
};
Console.WriteLine(result);
}
}
}
}
|