HtmlAgilityPack官方文档(六)【Utilities】

HtmlDocument 实用工具

HtmlDocument 方法

名称描述
DetectEncoding(Stream)Detects the encoding of an HTML stream.
DetectEncoding(TextReader)Detects the encoding of an HTML text provided on a TextReader.
DetectEncoding(String)Detects the encoding of an HTML file.
DetectEncodingAndLoad(String)Detects the encoding of an HTML document from a file first, and then loads the file.
DetectEncodingAndLoad(String, Boolean)Detects the encoding of an HTML document from a file first, and then loads the file.

public Encoding DetectEncoding(Stream stream)

检测HTML流的编码。DetectEncoding方法是HtmlAgilityPack.HtmlDocument 的成员

参数:

stream: 输入流。 不可能为null。

返回:

检测到的编码。

以下示例检测HTML流的编码。

var htmlNewDoc = new HtmlDocument();

FileStream newfs = new FileStream("Test.html", FileMode.Open);

var encoding = htmlNewDoc.DetectEncoding(newfs);

public Encoding DetectEncoding(TextReader reader)

检测TextReader上提供的HTML文本的编码。DetectEncoding方法是HtmlAgilityPack.HtmlDocument 的成员

参数:

reader: 用于提供HTML的TextReader。 不可能为null。

返回:

检测到的编码。

以下示例检测TextReader上提供的HTML文本的编码。

var htmlNewDoc = new HtmlDocument();

TextReader tr = File.OpenText("Test.html");

var encoding = htmlNewDoc.DetectEncoding(tr);

public Encoding DetectEncoding(string path)

检测HTML文件的编码。DetectEncoding方法是HtmlAgilityPack.HtmlDocument 的成员

参数:

path: 包含要检测的HTML文档的文件的路径。 不可能为null。

返回:

检测到的编码。

以下示例检测HTML文件的编码。

var htmlNewDoc = new HtmlDocument();

var encoding = htmlNewDoc.DetectEncoding("Test.html");

public void DetectEncodingAndLoad(string path)

首先从文件中检测HTML文档的编码,然后加载文件。 DetectEncodingAndLoad方法是HtmlAgilityPack.HtmlDocument 的成员

参数:

path: 要读取的完整文件路径。

以下示例首先检测HTML文件的编码,然后加载它。

var htmlNewDoc = new HtmlDocument();

htmlNewDoc.DetectEncodingAndLoad("Test.html");

public void DetectEncodingAndLoad(string path, bool detectEncoding)

Detects the encoding of an HTML document from a file first, and then loads the file. DetectEncodingAndLoad method is a member of HtmlAgilityPack.HtmlDocument
首先从文件中检测HTML文档的编码,然后加载文件。 DetectEncodingAndLoad方法是HtmlAgilityPack.HtmlDocument 的成员

参数:

path: 要读取的完整文件路径。不可能为null。
detectEncoding: 检测编码为true,否则为false。

以下示例首先检测HTML文件的编码,然后加载它。

var htmlNewDoc = new HtmlDocument();

htmlNewDoc.DetectEncodingAndLoad("Test.html", true);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值