// 获取登录页面的相关信息 public static void initAttributes() { client.DefaultRequestHeaders.Clear(); // CookieContainer c = new CookieContainer(); JwCrawler.client.DefaultRequestHeaders.Add( "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ); // 首先拿到route和JSESSIONID HttpResponseMessage res = client.GetAsync(loginPage).Result; CookieCollection cookies = handler.CookieContainer.GetCookies(new Uri(loginPage)); foreach (Cookie ck in cookies) { Console.WriteLine("cookie: " + ck.Value); } route = cookies.First().ToString(); // 设置cookie的值 JSESSIONID = cookies.Last().ToString(); var resStr = res.Content.ReadAsStreamAsync().Result; try { HtmlDocument doc = new HtmlDocument(); // Console.WriteLine(res.Content.ReadAsStringAsync().Result); doc.Load(resStr); HtmlNode node; node = doc.DocumentNode.SelectSingleNode("//input[@name='lt']"); JwCrawler.lt = node.Attributes["value"].Value; node = doc.DocumentNode.SelectSingleNode("//input[@name='dllt']"); JwCrawler.dllt = node.Attributes["value"].Value; node = doc.DocumentNode.SelectSingleNode("//input[@name='execution']"); JwCrawler.execution = node.Attributes["value"].Value; node = doc.DocumentNode.SelectSingleNode("//input[@name='_eventId']"); JwCrawler._eventId = node.Attributes["value"].Value; node = doc.DocumentNode.SelectSingleNode("//input[@name='rmShown']"); JwCrawler.rmShown = node.Attributes["value"].Value; node = doc.DocumentNode.SelectSingleNode("//input[@id='pwdDefaultEncryptSalt']"); JwCrawler.dynamicPwdEncryptSalt = node.Attributes["value"].Value; Console.WriteLine(lt); Console.WriteLine(dllt); Console.WriteLine(execution); Console.WriteLine(_eventId); Console.WriteLine(rmShown); Console.WriteLine(dynamicPwdEncryptSalt); } catch (Exception e) { Console.WriteLine(e.InnerException.Message); } }