Class HtmlWeb
- Namespace
- HtmlAgilityPack
- Assembly
- HtmlAgilityPack.dll
A utility class to get HTML document from HTTP.
public class HtmlWeb
- Inheritance
-
HtmlWeb
- Inherited Members
Constructors
HtmlWeb()
public HtmlWeb()
Fields
PostResponse
Occurs after an HTTP request has been executed.
public HtmlWeb.PostResponseHandler PostResponse
Field Value
PreHandleDocument
Occurs before an HTML document is handled.
public HtmlWeb.PreHandleDocumentHandler PreHandleDocument
Field Value
PreRequest
Occurs before an HTTP request is executed.
public HtmlWeb.PreRequestHandler PreRequest
Field Value
Properties
AutoDetectEncoding
Gets or Sets a value indicating if document encoding must be automatically detected.
public bool AutoDetectEncoding { get; set; }
Property Value
CacheOnly
Gets or Sets a value indicating whether to get document only from the cache. If this is set to true and document is not found in the cache, nothing will be loaded.
public bool CacheOnly { get; set; }
Property Value
CachePath
Gets or Sets the cache path. If null, no caching mechanism will be used.
public string CachePath { get; set; }
Property Value
FromCache
Gets a value indicating if the last document was retrieved from the cache.
public bool FromCache { get; }
Property Value
OverrideEncoding
Gets or sets the Encoding used to override the response stream from any web request
public Encoding OverrideEncoding { get; set; }
Property Value
RequestDuration
Gets the last request duration in milliseconds.
public int RequestDuration { get; }
Property Value
ResponseUri
Gets the URI of the Internet resource that actually responded to the request.
public Uri ResponseUri { get; }
Property Value
- Uri
StatusCode
Gets the last request status.
public HttpStatusCode StatusCode { get; }
Property Value
StreamBufferSize
Gets or Sets the size of the buffer used for memory operations.
public int StreamBufferSize { get; set; }
Property Value
UseCookies
Gets or Sets a value indicating if cookies will be stored.
public bool UseCookies { get; set; }
Property Value
UserAgent
Gets or Sets the User Agent HTTP 1.1 header sent on any webrequest
public string UserAgent { get; set; }
Property Value
UsingCache
Gets or Sets a value indicating whether the caching mechanisms should be used or not.
public bool UsingCache { get; set; }
Property Value
Methods
CreateInstance(string, string, XsltArgumentList, Type)
Creates an instance of the given type from the specified Internet resource.
public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type)
Parameters
htmlUrlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
xsltUrlstringThe URL that specifies the XSLT stylesheet to load.
xsltArgsXsltArgumentListAn System.Xml.Xsl.XsltArgumentList containing the namespace-qualified arguments used as input to the transform.
typeTypeThe requested type.
Returns
- object
An newly created instance.
CreateInstance(string, string, XsltArgumentList, Type, string)
Creates an instance of the given type from the specified Internet resource.
public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type, string xmlPath)
Parameters
htmlUrlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
xsltUrlstringThe URL that specifies the XSLT stylesheet to load.
xsltArgsXsltArgumentListAn System.Xml.Xsl.XsltArgumentList containing the namespace-qualified arguments used as input to the transform.
typeTypeThe requested type.
xmlPathstringA file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.
Returns
- object
An newly created instance.
CreateInstance(string, Type)
Creates an instance of the given type from the specified Internet resource.
public object CreateInstance(string url, Type type)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
typeTypeThe requested type.
Returns
- object
An newly created instance.
Get(string, string)
Gets an HTML document from an Internet resource and saves it to the specified file.
public void Get(string url, string path)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
pathstringThe location of the file where you want to save the document.
Get(string, string, WebProxy, NetworkCredential)
Gets an HTML document from an Internet resource and saves it to the specified file. - Proxy aware
public void Get(string url, string path, WebProxy proxy, NetworkCredential credentials)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
pathstringThe location of the file where you want to save the document.
proxyWebProxycredentialsNetworkCredential
Get(string, string, WebProxy, NetworkCredential, string)
Gets an HTML document from an Internet resource and saves it to the specified file. Understands Proxies
public void Get(string url, string path, WebProxy proxy, NetworkCredential credentials, string method)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
pathstringThe location of the file where you want to save the document.
proxyWebProxycredentialsNetworkCredentialmethodstringThe HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.
Get(string, string, string)
Gets an HTML document from an Internet resource and saves it to the specified file.
public void Get(string url, string path, string method)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
pathstringThe location of the file where you want to save the document.
methodstringThe HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.
GetCachePath(Uri)
Gets the cache file path for a specified url.
public string GetCachePath(Uri uri)
Parameters
uriUriThe url fo which to retrieve the cache path. May not be null.
Returns
- string
The cache file path.
GetContentTypeForExtension(string, string)
Gets the MIME content type for a given path extension.
public static string GetContentTypeForExtension(string extension, string def)
Parameters
extensionstringThe input path extension.
defstringThe default content type to return if any error occurs.
Returns
- string
The path extension's MIME content type.
GetExtensionForContentType(string, string)
Gets the path extension for a given MIME content type.
public static string GetExtensionForContentType(string contentType, string def)
Parameters
contentTypestringThe input MIME content type.
defstringThe default path extension to return if any error occurs.
Returns
- string
The MIME content type's path extension.
Load(string)
Gets an HTML document from an Internet resource.
public HtmlDocument Load(string url)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
Returns
- HtmlDocument
A new HTML document.
Load(string, string)
Loads an HTML document from an Internet resource.
public HtmlDocument Load(string url, string method)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
methodstringThe HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.
Returns
- HtmlDocument
A new HTML document.
Load(string, string, int, string, string)
Gets an HTML document from an Internet resource.
public HtmlDocument Load(string url, string proxyHost, int proxyPort, string userId, string password)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
proxyHoststringHost to use for Proxy
proxyPortintPort the Proxy is on
userIdstringUser Id for Authentication
passwordstringPassword for Authentication
Returns
- HtmlDocument
A new HTML document.
Load(string, string, WebProxy, NetworkCredential)
Loads an HTML document from an Internet resource.
public HtmlDocument Load(string url, string method, WebProxy proxy, NetworkCredential credentials)
Parameters
urlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
methodstringThe HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.
proxyWebProxyProxy to use with this request
credentialsNetworkCredentialCredentials to use when authenticating
Returns
- HtmlDocument
A new HTML document.
LoadHtmlAsXml(string, string, XsltArgumentList, XmlTextWriter)
Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter, after an XSLT transformation.
public void LoadHtmlAsXml(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, XmlTextWriter writer)
Parameters
htmlUrlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
xsltUrlstringThe URL that specifies the XSLT stylesheet to load.
xsltArgsXsltArgumentListAn XsltArgumentList containing the namespace-qualified arguments used as input to the transform.
writerXmlTextWriterThe XmlTextWriter to which you want to save.
LoadHtmlAsXml(string, string, XsltArgumentList, XmlTextWriter, string)
Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter, after an XSLT transformation.
public void LoadHtmlAsXml(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, XmlTextWriter writer, string xmlPath)
Parameters
htmlUrlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp". May not be null.
xsltUrlstringThe URL that specifies the XSLT stylesheet to load.
xsltArgsXsltArgumentListAn XsltArgumentList containing the namespace-qualified arguments used as input to the transform.
writerXmlTextWriterThe XmlTextWriter to which you want to save.
xmlPathstringA file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.
LoadHtmlAsXml(string, XmlTextWriter)
Loads an HTML document from an Internet resource and saves it to the specified XmlTextWriter.
public void LoadHtmlAsXml(string htmlUrl, XmlTextWriter writer)
Parameters
htmlUrlstringThe requested URL, such as "http://Myserver/Mypath/Myfile.asp".
writerXmlTextWriterThe XmlTextWriter to which you want to save to.