[VBNET] 抓取網頁部分內容

[VBNET] 抓取網頁部分內容 « 鄭子璉

很多網頁砍站軟體支援續傳、多線下載,多線下載觀念比較簡單,就是同一個檔利用多緒分別抓某個部分,再用二進位檔存取方式將抓得的結果直接寫入指定的範圍即可。

要知道怎樣做,可以先看規格書:
HTTP 1.0: RFC2068 14.36 節 Range
HTTP 1.1: RFC2616 14.35 節 Range

也就是說在 通訊協定中,檔頭加入:
Range: bytes=開始-結束
省略開始時,從 0 開始,省略結束時,自動抓到結尾。

我是認為寫程式前,應該先了解低階運作方式,通訊協定自然就是利用命令提示字元測試,例如輸入:
telnet tlcheng.twbbs.org 80
GET / HTTP/1.0
Range: bytes=100-199
傳回:
HTTP/1.1 206 Partial Content
Content-Length: 100
Content-Type: text/html
Content-Location: http://192.168.2.10/index.htm
Content-Range: bytes 100-199/3162
Last-Modified: Thu, 16 Oct 2008 08:32:25 GMT
Accept-Ranges: bytes
ETag: “e2437db7692fc91:1518″
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Thu, 16 Oct 2008 17:08:55 GMT
Connection: close
-equiv="Page-Exit" content="RevealTrans(Duration=0.5,Transition=23)">
憸函此蝘凵?撽ⓗ??毡<br />遺失與主機的連線。<br />C:><br />由上可知,很明確的傳回指定的範圍。<br /> <br />我們可以選擇的類別有 WebClient / WebRequest / HttpWebRequest ,在屬性 Headers 中的註解有提到:<br /><br />WebHeaderCollection 類別通常是經由 WebRequest.Headers 或 WebResponse.Headers 來存取。某些通用標頭會視為受限制的,並會直接由 API 公開 (例如,Content-Type) 或是由系統保護,而且無法變更。 </blockquote>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 13 + 5 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)