httpmodule通過httpfilter獲取返回的網頁內容
自定義httpmodule裡面:
public class CatchTextStream : Streampublic virtual void Init(HttpApplication app) { // WARNING! This does not work with Windows authentication! // If you are using Windows authentication, change to app.BeginRequest app.BeginRequest += (sender, e) => { app.Context.Response.Filter = new CatchTextStream(app.Response.Filter); }; }
{
private Stream output;
public CatchTextStream(Stream s)
{
output = s;
}
public override bool CanRead
{
get { return output.CanRead; }
}
public override bool CanSeek
{
get { return output.CanSeek; }
}
public override bool CanWrite
{
get { return output.CanWrite; }
}
public override void Flush()
{
output.Flush();
}
public override long Length
{
get { return output.Length; }
}
public override long Position
{
get { return output.Position; }
set { output.Position = value; }
}
public override int Read(byte[] buffer, int offset, int count)
{
return output.Read(buffer, offset, count);
}
public override long Seek(long offset, SeekOrigin origin)
{
return output.Seek(offset, origin);
}
public override void SetLength(long value)
{
output.SetLength(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
StringComparison ignore = StringComparison.CurrentCultureIgnoreCase;
if (HttpContext.Current != null)
{
HttpContext context = HttpContext.Current;
if (context.Response.ContentType.Equals("text/html", ignore))
{
Encoding encoding = context.Response.ContentEncoding;
//此處獲取返回的HTML內容
string html = encoding.GetString(buffer, offset, count);
byte[] bytes = encoding.GetBytes(html);
output.Write(bytes, 0, bytes.Length);
else
output.Write(buffer, offset, count);
}
}
}
相關推薦
httpmodule通過httpfilter獲取返回的網頁內容
自定義httpmodule裡面:public virtual void Init(HttpApplication app) { // WARNING! This does not work with Windows authenti
java通過URL獲取文本內容
file ear null 抓取 output copy pro 技術 public 原文地址https://www.cnblogs.com/myadmin/p/7634262.html public static String readFileByUrl(String
finecms首頁獲取單網頁內容
首頁獲取單網頁內容 {$cats[欄目id][content]} {strcut($cats[ID]['content'],字數,'...')}{strcut(,350)} //htmlspecialchars_decode:把一些預定義的 HTML 實體轉換為字元 strip_tags
Android通過WebView獲取解析html內容
童話美景 概述 在Android開發過程中,我們可能需要做一些模擬操作,可能需要獲取HTML頁面的一些資訊,此時就需要藉助重寫WebViewClient的onPageFinished方法,在onPageFinished中載入一段js程式碼,j
C/C++程式實現通過http代理訪問網頁內容
公司通過代理上網,C程式直接通過發http請求不能獲取網頁內容,故實現了下通過代理訪問http網頁的一個測試程式。 程式很簡單,有幾個重點 先通過socket直接連線代理伺服器 向代理伺服器傳送HTTP的CONNECT標頭,格式為CONNECT www.bai
DNS輪詢 PHP獲取遠端網頁內容的函式
PHP獲取遠端網頁內容有多種方式,例如用自帶的file_get_contents、fopen等函式。 <?php echo file_get_contents("http://blog.s135.com/abc.php"); ?> 但是,在DNS
beautifulsoup通過id獲取指定元素內容
<tr style="background-color:#fff;"> <td colspan="2" align=left valign="top"> <table id="zoom2" width="94%" bor
python獲取完整網頁內容(即包括js動態載入的):selenium+phantomjs
在上一篇文章(http://blog.csdn.net/Trisyp/article/details/78732630)中我們利用模擬開啟瀏覽器的方法模擬點選網頁中的載入更多來實現動態載入網頁並獲取網
php通過登入後的cookie以及使用者代理然後通過curl獲取網頁內容
function curl_get_https($url, $data=array(), $header=array(), $timeout=30){ $ch = curl_init(); curl_setopt($ch, CURLOPT_
iOS 通過url獲取網頁文字內容
今天突然有一個需求, 第二個頁面要顯示一個網頁,第一個頁面要顯示圖片標題或者簡介等內容,但是!後臺僅僅返回了一個URL!這就意味著我必須在第一個頁面自己通過URL拿到網頁內部我需要的內容.這裡就不詳細說怎麼拿到title或者圖片之類的了,我的需求是拿到文章內容的文字部
java中通過url獲取網頁內容,中文顯示是亂碼
URLConnection context = url.openConnection(); InputStream in = context.getInputStream(); BufferedRea
vc++使用IWinHttpRequest獲取網頁內容亂碼
[0 網頁 unicode code com box get ant 解決方法 mfc項目的字符集為unicode字符集 亂碼前代碼: CString rspStr = pHttpReq->ResponseText; MessageBox(rspStr); 亂碼效
通過request獲取網頁資訊 通過BeautifulSoup剖析網頁元素
獲取網頁 alink his odi res req 特定 bsp css屬性 import requests newsUrl =‘http://news.sina.com.cn/china/‘ res = requests.get(newsUrl) res.encod
獲取WebView加載的網頁內容並進行動態修改
datawit cli cap jsoup 動態修改 成功 scale 技術 parse http://www.jianshu.com/p/3f207a8e32cb 【Android】WebView讀取本地圖片 http://www.cnblogs.com/kimmy/p/
php 通過curl獲取遠程數據,返回的是一個數組型的字符串,高手幫忙如何將這個數組類型的字符串變成數組。
bsp 選項 con 獲取 pan 如果 clas exe transfer 如 Array([0] => Array([0] => Array([kd_status] => 已簽收[kd_time] => 2014-04-30 18:59:43 [
C# HttpClient Get獲取網頁內容
獲取網頁 lec net IV 內容 pen style 網頁 pac 1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq;
nodejs 使用 body-parser 獲取網頁內容
parse nodejs 網頁 url end func body parser .post var bodyParser = require(‘body-parser‘); var urlencodedParser = bodyParser.urlencoded({
php抓取網頁內容,獲取網頁資料
php通過simple_html_dom實現抓取網頁內容,獲取核心網頁資料,將網頁資料寫入本地 xxx.json 檔案 其程式碼實現邏輯: 1. 引入simple_html_dom.php檔案 require_once 'simple_ht
關於java獲取網頁內容
最近專案需求,做一些新聞站點的爬取工作。1.簡單的jsoup爬取,靜態頁面形式; String url="a.atimo.cn";//靜態頁面連結地址Document doc = Jsoup.connect(url).userAgent("Mozilla").timeout(4000).get();
關於C# 使用Xpath路徑(HtmlAgilityPack)對網頁內容查詢獲取的方法。(程式為.ashx的一般處理程式)
先貼程式碼: using System; using System.Web; using Newtonsoft.Json; using System.Net; using System.IO; using System.Text; using System.Text.Reg