• System.Net.Http.HttpClient 模拟登录并抓取弹窗数据


                using (System.Net.Http.HttpClient httpClient = new HttpClient())
                {
    
    
                    httpClient.MaxResponseContentBufferSize = 256000;
                    httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
                    httpClient.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");
    
    
                    Console.WriteLine($"登录提交:");
                    var response = httpClient.PostAsJsonAsync("http://xxxxx/account/login", new User() { account = @"admin", password = @"admin" }).Result;
                    Console.WriteLine($"Response:{response.Content.ReadAsStringAsync().Result}");
                    Console.WriteLine($"主界面:");
                    var get = httpClient.GetAsync("http://xxxxx/#pane=Dashboard");
                    get.Wait(1000);
    
    
                    Console.WriteLine($"弹窗界面:");
                    DateTime curr = new DateTime(2019, 12, 6);
                    string name = $"{curr:yyyy-MM-dd}";
    
    
                    Console.WriteLine($"取记录=>{name}:");
                    get = httpClient.GetAsync("http://xxxxx/Report/AddReport?Date=" + name + "&type=add");
                    //将 html 写入到本地
                    Write(name + ".html", get.Result.Content.ReadAsStringAsync().Result);
                    Console.WriteLine(get.Result.Content.ReadAsStringAsync().Result);
    
    
    
                    }
    
                }
    

      

                                    Console.WriteLine($"重复值:{item.dailyContent}");
                                    var id = li.FirstOrDefault(q => q.dailyContent == item.dailyContent)?.dailyDetailId;
                                    Console.WriteLine($"首个Id:{id}");
    
                                    Dictionary<string, string> del = new Dictionary<string, string>();
                                    del.Add("Id",id);
                                    var ppp= httpClient.PostAsync("http://xxxxx/Report/Delete", new FormUrlEncodedContent(del)).Result;
                                    Console.WriteLine($"删除状态:{ppp.StatusCode == System.Net.HttpStatusCode.OK}");
    

      

  • 相关阅读:
    ORACLE11G 字符集更改(这里更改为AL32UTF8)
    linux 安装jdk1.8
    oracle的 listagg() WITHIN GROUP ()函数使用
    数据库事务中的隔离级别和锁以及spring @Transactional注解参数详解
    java读取Oracle中大字段数据(CLOB)的方法
    oracle常用函数_时间
    案例-todolist计划列表【添加计划】
    案例-todolist计划列表【显示列表】
    案例-todolist计划列表[基本代码]
    vue 阻止元素的默认行为
  • 原文地址:https://www.cnblogs.com/honk/p/12883737.html
Copyright © 2020-2023  润新知