zoukankan      html  css  js  c++  java
  • 油管无版权音频抓包纪要

    每次请求需要cookie  请求方式是get

    使用HttpWebRequest 请求,cookie直接是字符串的方式加入header  支持https请求方式.返回字符串,然后对返回值过滤取下载地址等信息
     private static readonly string DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
            /// <summary>  
            /// 创建GET方式的HTTP请求  
            /// </summary>  
            /// <param name="url">请求的URL</param>  
            /// <param name="timeout">请求的超时时间</param>  
            /// <param name="userAgent">请求的客户端浏览器信息,可以为空</param>  
            /// <param name="cookies">随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空</param>  
            /// <returns></returns>  
            public static string GetContent(string cookie, string url)
            {
                string content;
                HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(url);
                httpRequest.Headers.Add("Cookie", cookie);
                httpRequest.Referer = url;
                httpRequest.UserAgent = DefaultUserAgent;// "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36";
                httpRequest.Accept = "*/*";
                httpRequest.ContentType = "application/x-www-form-urlencoded";
                httpRequest.Method = "GET";
               // httpRequest.Headers.Add("accept-encoding", "gzip, deflate, br");
               // httpRequest.Headers.Add("accept-language", "zh-CN,zh;q=0.9");   //此处不需要设置,设置完了会出现乱码
                httpRequest.Referer = "https://www.youtube.com/audiolibrary/music?ar=1584199017054&nv=1";
    
                HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
    
                using (Stream responsestream = httpResponse.GetResponseStream())
                {
    
                  //  using (StreamReader sr = new StreamReader(responsestream, System.Text.Encoding.Default))
                    using (StreamReader sr = new StreamReader(responsestream, System.Text.Encoding.UTF8))   //此处编码要设置成utf8要不中文有乱码
                    {
                        content = sr.ReadToEnd();
                    }
                }
    
                return content;
            }

     下边是乱码出现的疑问, ios

    en_US.UTF-8:你说英语,你在美国,字符集是utf-8
    zh_CN.UTF-8:你说中文,你在中国,字符集是utf-8

    如果你的LANG环境变量是en_US.UTF-8,那么系统的菜单、程序的工具栏语言、输入法默认语言就都是英文的。

    如果你的LANG环境变量是zh_CN.UTF-8,那么系统的菜单、程序的工具栏语言、输入法默认语言就都是中文的。

    这两天做了一个获取cookie并且携带此cookie去请求另外一个url地址,中间携带cookie用了两种方式:
    1. httpRequest.CookieContainer= cookie (此cookie为一个cookie容器对象)
    2.httpRequest.Headers.Add("Cookie", cookie) (此cookie为一个cookie字符串)

    测试结果:1种方式cookie失效并且丢失。2种方式携带成功并且可以成功显示已登录。

    原因待查,记录下。
    说明:也可能cookie容器设置的方式有问题。

    附上代码:


    public class Login { public string GetCookie(string postString, string postUrl) { CookieContainer cookie = new CookieContainer(); HttpWebRequest httpRequset = (HttpWebRequest)HttpWebRequest.Create(postUrl);//创建http 请求 httpRequset.CookieContainer = cookie;//设置cookie httpRequset.Method = "POST";//POST 提交 httpRequset.KeepAlive = true; httpRequset.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"; httpRequset.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; httpRequset.ContentType = "application/x-www-form-urlencoded";//以上信息在监听请求的时候都有的直接复制过来 httpRequset.Referer = "http://my.qianlima.com/login.jsp"; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postString); httpRequset.ContentLength = bytes.Length; Stream stream = httpRequset.GetRequestStream(); stream.Write(bytes, 0, bytes.Length); stream.Close();//以上是POST数据的写入 HttpWebResponse httpResponse = (HttpWebResponse)httpRequset.GetResponse();//获得 服务端响应 var str = cookie.GetCookieHeader(httpRequset.RequestUri); return str;//拿到cookie } public string GetContent(string cookie, string url) { string content; HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(url); httpRequest.Headers.Add("Cookie", cookie); httpRequest.Referer = url; httpRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"; httpRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; httpRequest.ContentType = "application/x-www-form-urlencoded"; httpRequest.Method = "GET"; HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (Stream responsestream = httpResponse.GetResponseStream()) { using (StreamReader sr = new StreamReader(responsestream, System.Text.Encoding.Default)) { content = sr.ReadToEnd(); } } return content; } }
    最后就是获取到json数据 在线编辑一下.生成实体类,很方便
    https://www.sojson.com/

     先校验/格式化

    一行代码转换存入类实体

      Root rt = JsonConvert.DeserializeObject<Root>(content);


    复制代码
  • 相关阅读:
    百度开源其NLP主题模型工具包,文本分类等场景可直接使用L——LDA进行主题选择本质就是降维,然后用于推荐或者分类
    谷歌开源可视化工具Facets,将用于人+AI协作项目研究——无非就是一个用于特征工程探索的绘图工具集,pandas可以做的
    机器学习案例 特征组合——高帅富 冷启动——从微博等其他渠道搜集数据进行机器学习 用户年龄——线性分段处理
    pyspark MLlib踩坑之model predict+rdd map zip,zip使用尤其注意啊啊啊!
    [038] 微信公众帐号开发教程第14篇-自定义菜单的创建及菜单事件响应
    [037] 微信公众帐号开发教程第13篇-图文消息全攻略
    [036] 微信公众帐号开发教程第12篇-符号表情的发送(下)(转)
    [035] 微信公众帐号开发教程第11篇-符号表情的发送(上)(转)
    [034] 微信公众帐号开发教程第10篇-解析接口中的消息创建时间CreateTime(转)
    [033] 微信公众帐号开发教程第9篇-QQ表情的发送与接收(转)
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/12501474.html
Copyright © 2011-2022 走看看