1
2 3 4 5 6 7 8 9 |
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Url);
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; request.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; request.ContentType = "application/x-www-form-urlencoded"; request.KeepAlive = true; //此处换上每集的网址 |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
/// <summary>
/// 抓取网页内容 /// </summary> /// <param name="Url">网址</param> /// <param name="myEncoding">编码方式</param> /// <param name="myEncoding">请求的网址</param> /// <returns></returns> public string GetHtml(string Url, Encoding myEncoding, string Referer) { string HtmlString = ""; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Url); request.Timeout = ; request.KeepAlive = true; request.AllowWriteStreamBuffering = true; request.Credentials = System.Net.CredentialCache.DefaultCredentials; request.MaximumResponseHeadersLength = -; request.Referer = Referer; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; request.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; request.ContentType = "application/x-www-form-urlencoded"; request.Method = "GET"; try { using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream resStream = response.GetResponseStream(); StreamReader sr = new StreamReader(resStream, myEncoding); HtmlString = sr.ReadToEnd(); } } catch { } return HtmlString; } /// <summary> /// 下载评书的后台线程 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bw_Download_DoWork(object sender, DoWorkEventArgs e) { //图书下载的本地路径 string LocalPath = e.Argument.ToString(); //查询出所有未下载的剧集 //并行循环 //抓取剧集的详细页内容 //播放mp3的网页地址 //评书的实际播放页面实际是嵌在详细页中的一个frame框架中,所以需要继续抓取播放评书的页面。 //抓取下载MP3所需的Key && ms_Down.Success) WebClient client = new WebClient(); private void bw_Download_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) ) using (BackgroundWorker bw_Download = new BackgroundWorker()) |