/// <summary> /// Loads an HTML document from an Internet resource. /// </summary> /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param> /// <param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param> /// <returns>A new HTML document.</returns> public HtmlDocument Load(string url, string method) { Uri uri = new Uri(url); HtmlDocument doc; if ((uri.Scheme == Uri.UriSchemeHttps) || (uri.Scheme == Uri.UriSchemeHttp)) { doc = LoadUrl(uri, method); } else { if (uri.Scheme == Uri.UriSchemeFile) { doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionAutoCloseOnEnd = true; doc.DetectEncodingAndLoad(url, _autoDetectEncoding); } else { throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); } } if (PreHandleDocument != null) { PreHandleDocument(doc); } return(doc); }
// // <add key="AppNamePath" value="//div[@class='details']//a[@class='title']" /> // <add key="PricePath" value="//div[@class='reason-set']//button[@class='price buy']/span" /> // <add key="BundleIDPath" value="//div[@class='details']//a[@class='title']" /> // <add key="BundleIDAttr" value="href" /> // <add key="BundleIDRegex" value="(?:id=([^&]+))" /> // <add key="AppIDPath" value="//div[@class='details']//a[@class='title']" /> // <add key="AppIDAttr" value="href" /> // <add key="AppIDRegex" value="(?:id=([^&]+))" /> public static void CheckHtml() { HtmlDocument doc = new HtmlDocument(); string path = @"C:\Users\Pat\Documents\SharpDevelop Projects\IdeaTests\googletest.htm"; doc.DetectEncodingAndLoad(path); HtmlNodeCollection containers = doc.DocumentNode.SelectNodes(@"//*[@class='cluster-container']/*/div[@class='card-list']"); Console.WriteLine(containers.Count ); foreach (var node in containers) { HtmlNodeCollection appNames = node.SelectNodes(@"//div[@class='details']//a[@class='title']"); Console.WriteLine("appname: " + appNames.Count); } }
private HtmlDocument LoadUrl(Uri uri, string method) { HtmlDocument doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionFixNestedTags = true; _statusCode = Get(uri, method, null, doc); if (_statusCode == HttpStatusCode.NotModified) { // read cached encoding doc.DetectEncodingAndLoad(GetCachePath(uri)); } return(doc); }
private HtmlDocument LoadUrl(Uri uri, string method) { HtmlDocument doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionFixNestedTags = true; _statusCode = Get(uri, method, null, doc); if (_statusCode == HttpStatusCode.NotModified) { // read cached encoding doc.DetectEncodingAndLoad(GetCachePath(uri)); } return doc; }
/// <summary> /// Loads an HTML document from an Internet resource. /// </summary> /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param> /// <param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param> /// <returns>A new HTML document.</returns> public HtmlDocument Load(string url, string method) { Uri uri = new Uri(url); HtmlDocument doc; if ((uri.Scheme == Uri.UriSchemeHttps) || (uri.Scheme == Uri.UriSchemeHttp)) { doc = LoadUrl(uri, method); } else { if (uri.Scheme == Uri.UriSchemeFile) { doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionAutoCloseOnEnd = true; doc.DetectEncodingAndLoad(url, _autoDetectEncoding); } else { throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); } } if (PreHandleDocument != null) { PreHandleDocument(doc); } return doc; }
private HtmlDocument LoadUrl(Uri uri, string method, IWebProxy proxy, ICredentials creds) { var doc = new HtmlDocument { OptionAutoCloseOnEnd = false, OptionFixNestedTags = true }; StatusCode = Get(uri, method, null, doc, proxy, creds); if (StatusCode == HttpStatusCode.NotModified) { // read cached encoding doc.DetectEncodingAndLoad(GetCachePath(uri)); } return doc; }
/// <summary> /// Loads an HTML document from an Internet resource. /// </summary> /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param> /// <param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param> /// <param name="proxy">Proxy to use with this request</param> /// <param name="credentials">Credentials to use when authenticating</param> /// <returns>A new HTML document.</returns> public HtmlDocument Load(string url, string method, IWebProxy proxy, NetworkCredential credentials) { var uri = new Uri(url); HtmlDocument doc; if ((uri.Scheme.ToLower() == "https") || (uri.Scheme.ToLower() == "http")) { doc = LoadUrl(uri, method, proxy, credentials); } else { if (uri.Scheme.ToLower() == "file") { doc = new HtmlDocument { OptionAutoCloseOnEnd = false }; doc.OptionAutoCloseOnEnd = true; doc.DetectEncodingAndLoad(url, AutoDetectEncoding); } else { throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); } } PreHandleDocument?.Invoke(doc); return doc; }
/// <summary> /// Loads an HTML document from an Internet resource. /// </summary> /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param> /// <param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param> /// <returns>A new HTML document.</returns> public HtmlDocument Load(string url, string method) { var uri = new Uri(url); HtmlDocument doc; if ((uri.Scheme.ToLower() == "https") || (uri.Scheme.ToLower() == "http")) { doc = LoadUrl(uri, method, null, null); } else { if (uri.Scheme.ToLower() == "file") { doc = new HtmlDocument { OptionAutoCloseOnEnd = false }; doc.OptionAutoCloseOnEnd = true; if (OverrideEncoding != null) doc.Load(url, OverrideEncoding); else doc.DetectEncodingAndLoad(url, AutoDetectEncoding); } else { throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); } } PreHandleDocument?.Invoke(doc); return doc; }
private HtmlDocument LoadUrl(Uri uri, string method, WebProxy proxy, NetworkCredential creds) { HtmlDocument doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionFixNestedTags = true; if (OptionMaxNestedChildNodes > 0) doc.OptionMaxNestedChildNodes = OptionMaxNestedChildNodes; _statusCode = Get(uri, method, null, doc, proxy, creds); if (_statusCode == HttpStatusCode.NotModified) { // read cached encoding doc.DetectEncodingAndLoad(GetCachePath(uri)); } return doc; }
/// <summary> /// Loads an HTML document from an Internet resource. /// </summary> /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param> /// <param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param> /// <param name="proxy">Proxy to use with this request</param> /// <param name="credentials">Credentials to use when authenticating</param> /// <returns>A new HTML document.</returns> public HtmlDocument Load(string url, string method, WebProxy proxy, NetworkCredential credentials) { Uri uri = new Uri(url); HtmlDocument doc; if ((uri.Scheme == Uri.UriSchemeHttps) || (uri.Scheme == Uri.UriSchemeHttp)) { doc = LoadUrl(uri, method, proxy, credentials); } else { if (uri.Scheme == Uri.UriSchemeFile) { doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionAutoCloseOnEnd = true; if (OptionMaxNestedChildNodes > 0) doc.OptionMaxNestedChildNodes = OptionMaxNestedChildNodes; doc.DetectEncodingAndLoad(url, _autoDetectEncoding); } else { throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); } } if (PreHandleDocument != null) { PreHandleDocument(doc); } return doc; }
public static List<TextureInfo> Read(string fileName) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.DetectEncodingAndLoad(fileName, true); //htmlDoc. HtmlNode Plist = htmlDoc.DocumentNode.Element("plist"); HtmlNodeCollection dicNodes = Plist.ChildNodes["dict"].ChildNodes[3].ChildNodes; int count = dicNodes.Count / 2; int i = 0; var texInfoes = new List<TextureInfo>(); string key = null; //var value = null; var dic = new Dictionary<string, Dictionary<string, string>>(); foreach (HtmlNode node in dicNodes) { if (node.Name[0] == '#') continue; if (node.Name[0] == 'k') { key = node.InnerHtml; } else { var value = new Dictionary<string, string>(); string subKey = null; string subValue = null; foreach (HtmlNode infoNode in node.ChildNodes) { if (infoNode.Name[0] == '#') continue; if (infoNode.Name[0] == 'k') { subKey = infoNode.InnerHtml; } else { subValue = infoNode.InnerHtml == string.Empty ? infoNode.Name : infoNode.InnerHtml; value.Add(subKey, subValue); subKey = null; subValue = null; } } dic.Add(key, value); key = null; value = null; } } foreach (string item in dic.Keys) { TextureInfo texInfo = new TextureInfo(); texInfo.fileName = item; var value = dic[item]; //获取FrameRect texInfo.texRect = GetFrameRect(value[plistKeyInfo.FrameRect]); //计算并存储offsetRect texInfo.offset = new point(0, 0); GetTowNumber(value[plistKeyInfo.Offset], out texInfo.offset.x, out texInfo.offset.y); //获取SourceSize int width; int height; GetTowNumber(value[plistKeyInfo.SourceSize], out width, out height); texInfo.sourceSize = new size(width, height); // Console.WriteLine("{0}: {1}, {2} ; {3}, {4}", // tempinfo.fileName, // tempinfo.texRect.X, tempinfo.texRect.Y, // tempinfo.texRect.Width, tempinfo.texRect.Height // ); //计算实际的innerRect的值 texInfo.innerRect = new rect(0, 0, 0, 0); texInfo.innerRect.Width = texInfo.texRect.Width; texInfo.innerRect.Height = texInfo.texRect.Height; texInfo.innerRect.X = (texInfo.sourceSize.Width - texInfo.texRect.Width) / 2 + texInfo.offset.x; texInfo.innerRect.Y = (texInfo.sourceSize.Height - texInfo.texRect.Height) / 2 - texInfo.offset.y; texInfoes.Add(texInfo); } return texInfoes; }
private HtmlDocument LoadUrl(Uri uri, string method, WebProxy proxy, NetworkCredential creds) { HtmlDocument doc = new HtmlDocument(); doc.OptionAutoCloseOnEnd = false; doc.OptionFixNestedTags = true; this._statusCode = this.Get(uri, method, (string) null, doc, (IWebProxy) proxy, (ICredentials) creds); if (this._statusCode == HttpStatusCode.NotModified) doc.DetectEncodingAndLoad(this.GetCachePath(uri)); return doc; }
/// <summary> /// Loads an HTML document from an Internet resource. /// /// </summary> /// <param name="url">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param><param name="method">The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND.</param><param name="proxy">Proxy to use with this request</param><param name="credentials">Credentials to use when authenticating</param> /// <returns> /// A new HTML document. /// </returns> public HtmlDocument Load(string url, string method, WebProxy proxy, NetworkCredential credentials) { Uri uri = new Uri(url); HtmlDocument document; if (uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp) { document = this.LoadUrl(uri, method, proxy, credentials); } else { if (!(uri.Scheme == Uri.UriSchemeFile)) throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); document = new HtmlDocument(); document.OptionAutoCloseOnEnd = false; document.OptionAutoCloseOnEnd = true; document.DetectEncodingAndLoad(url, this._autoDetectEncoding); } if (this.PreHandleDocument != null) this.PreHandleDocument(document); return document; }