當前位置: 首頁>>代碼示例>>C#>>正文


C# Forms.HtmlDocument類代碼示例

本文整理匯總了C#中System.Windows.Forms.HtmlDocument的典型用法代碼示例。如果您正苦於以下問題:C# HtmlDocument類的具體用法?C# HtmlDocument怎麽用?C# HtmlDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HtmlDocument類屬於System.Windows.Forms命名空間,在下文中一共展示了HtmlDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AttachValueToDataSource

 public static void AttachValueToDataSource(DataSet ds, HtmlDocument doc)
 {
     LoggingService.DebugFormatted("綁定HTML表單數據:{0} 到數據源...", new object[] { doc.Url });
     foreach (string str in tags)
     {
         HtmlElementCollection elementsByTagName = doc.GetElementsByTagName(str);
         foreach (HtmlElement element in elementsByTagName)
         {
             DataRow row;
             string attribute = element.GetAttribute("dbtable");
             string str3 = element.GetAttribute("dbcolumn");
             if (GetDataRow(ds, attribute, out row) && (row != null))
             {
                 if (row.RowState == DataRowState.Unchanged)
                 {
                     row.SetModified();
                 }
                 if (!(string.IsNullOrEmpty(str3) || !row.Table.Columns.Contains(str3)))
                 {
                     string str4 = element.GetAttribute("value").Trim();
                     row[str3] = (str4 == string.Empty) ? Convert.DBNull : str4;
                     LoggingService.DebugFormatted("設置表:{0}列:{1}的值為:{2}", new object[] { attribute, str3, str4 });
                 }
             }
         }
     }
 }
開發者ID:vanloc0301,項目名稱:mychongchong,代碼行數:27,代碼來源:WebBrowserExtensions.cs

示例2: LoadJsFile

        public static bool LoadJsFile(HtmlDocument doc, string js)
        {
            bool noErr = true;
            string file = String.Empty;
            try
            {
                string[] files = js.Split(new char[] { ',' });
                foreach (string f in files)
                {
                    file = GlobalVar.AppPath + "res\\" + f + ".js";

                    string s = Utility.ReadFile(file);
                    noErr &= !String.IsNullOrEmpty(s);

                    if(String.IsNullOrEmpty(s))
                        GlobalVar.Log.LogError("取得文件內空為空!",file);

                    ExecScript(doc, s);

                }
                doc.Write("<script language='javascript'>alert('hello');</script>");

            }

            catch (System.Exception )
            {
                MessageBox.Show("load [" + file + "] error");
                return false;
            }
            return noErr;
        }
開發者ID:kener1985,項目名稱:MyGitHubProj,代碼行數:31,代碼來源:ScriptUtility.cs

示例3: DOMTreeToXml

        private static XmlDocument DOMTreeToXml(HtmlDocument htmlDoc)
        {
            XmlDocument result = new XmlDocument();
            if(htmlDoc != null &&
               htmlDoc.Body != null &&
               htmlDoc.Body.Parent != null)
            {
              	    HtmlElement topHtml = htmlDoc.Body.Parent;
              	    using (StringReader sReader = new StringReader(topHtml.OuterHtml))
              	    {
              	      using (StringWriter errorLog = new StringWriter())
              	      {
              	        Sgml.SgmlReader reader = new Sgml.SgmlReader();
              	        reader.ErrorLog = errorLog;
              	        reader.InputStream = sReader;
              	        using (StringReader dtdReader = new StringReader(Properties.Resources.WeakHtml))
              	          reader.Dtd = Sgml.SgmlDtd.Parse(null, "HTML", null, dtdReader, null, null, reader.NameTable);

              	        result.Load(reader);
              	        errorLog.Flush();
              	        Console.WriteLine(errorLog.ToString());
              	      }
              	    }
            }
              	  return result;
        }
開發者ID:rushit-dawda,項目名稱:content-extractor,代碼行數:26,代碼來源:WebDocument.cs

示例4: DownloadInfo

 public DownloadInfo(Uri projectUrl, Uri articleUrl, HtmlDocument htmlDocument)
 {
     m_projectUrl = projectUrl;
     m_articleUrl = articleUrl;
     m_htmlDocument = htmlDocument;
     ParseCookies(htmlDocument.Cookie);
 }
開發者ID:bcokur,項目名稱:mydotnetsamples,代碼行數:7,代碼來源:DownloadInfo.cs

示例5: Download

        public Download(HtmlDocument document, string key, string url, string filename)
        {
            this.url = url;
            this.key = key;
            this.document = document;
            target = Path.Combine(Path.GetTempPath(), filename);
            if (File.Exists(target))
                status = DownloadStatus.DOWNLOADED;
            else
                status = DownloadStatus.AVAILABLE;

            downloadBGWorker = new BackgroundWorker()
            {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = true
            };

            downloadBGWorker.DoWork += RunDownload;
            downloadBGWorker.ProgressChanged += UpdateProgress;
            downloadBGWorker.RunWorkerCompleted += DownloadFinished;

            extractBGWorker = new BackgroundWorker();

            extractBGWorker.DoWork += DoExtraction;
            extractBGWorker.RunWorkerCompleted += ExtractionFinished;
        }
開發者ID:patthoyts,項目名稱:OpenRA,代碼行數:26,代碼來源:Download.cs

示例6: ParseSeries

        private Series ParseSeries(HtmlDocument doc)
        {
            var result = new Series();
            result.Title = Find(FindTitle, doc);
            result.Description = Find(FindDescription, doc);

            return result;
        }
開發者ID:ngprice,項目名稱:wcscrape,代碼行數:8,代碼來源:Index.cs

示例7: DisplayInTree

        /// <summary>
        /// Display an HTML document in the tree view, organizing the tree
        /// in accordance with the Document Object Model (DOM)
        /// </summary>
        /// <param name="docResponse">the document to display</param>
        /// <remarks><para>Called by the thread.start to set up for filling the DOM tree</para>
        /// Has to be passed as an object for the ParameterizedThreadStart</remarks>
        public void DisplayInTree(HtmlDocument docResponse)
        {
            HtmlElementCollection elemColl = docResponse.GetElementsByTagName("html");

            _treeView.Nodes.Clear();
            var rootNode = new TreeNode("Web response") {Tag = -1};
            _treeView.Nodes.Add(rootNode);
            FillDomTree(elemColl, rootNode, 0);
        }
開發者ID:jcvlcek,項目名稱:DenniHlasatelDeathIndexExplorer,代碼行數:16,代碼來源:TreeViewWrapper.cs

示例8: FindTitle

        private string FindTitle(HtmlDocument doc)
        {
            var result = String.Empty;

            IQueryable<HtmlElement> h1HEC = doc.GetElementsByTagName("h1").AsQueryable().Cast<HtmlElement>();
            var titleElement = h1HEC.First(e => e.GetAttribute("class") == "title");

            return result;
        }
開發者ID:ngprice,項目名稱:wcscrape,代碼行數:9,代碼來源:Index.cs

示例9: GetOrCreateDocumentHandle

        public static HtmlDocumentHandle GetOrCreateDocumentHandle(HtmlDocument htmlDocument)
        {
            var guidObj = htmlDocument.InvokeScript (c_getDocumentIdentification);

              var docID = guidObj != null ? new HtmlDocumentHandle (Guid.Parse (guidObj.ToString())) : new HtmlDocumentHandle (Guid.NewGuid());

              htmlDocument.InvokeScript (c_addDocumentIdentification, new object[] { docID.ToString() });
              return docID;
        }
開發者ID:rubicon-oss,項目名稱:DesktopGap,代碼行數:9,代碼來源:DocumentIdentifier.cs

示例10: Create

        public static IBoodProduct Create(HtmlDocument doc)
        {
            try {
                var all = doc.All.Cast<HtmlElement>();
                var imgs = doc.Images.Cast<HtmlElement>();

                var img = GetElement(all, "IMG", "className", "main-prod-img") ?? imgs.FirstOrDefault(i => i.OuterHtml.Contains("class=main-prod-img"));

                var prodName = string.Empty;
                var prodImage = string.Empty;
                if (img != null) {
                    prodName = img.GetAttribute("alt");
                    prodImage = img.GetAttribute("src");
                }

                var spanOldPrice = GetElement(all, "SPAN", "className", "old-price");
                decimal oldPrice = 0;
                try {
                    oldPrice = decimal.Parse(spanOldPrice.InnerText, System.Globalization.NumberStyles.Currency);
                }
                catch { }

                var spanOurPrice = GetElement(all, "P", "className", "our-price");
                decimal ourPrice = 0;
                decimal shippingCost = 0;
                try {
                    // "iBOOD PrijsNu! € 149,95 + (8,95) "
                    var priceParts = spanOurPrice.InnerText.Split(new char[] {'€', ' ', '+', '(' ,')'}, StringSplitOptions.RemoveEmptyEntries );
                    shippingCost   = decimal.Parse(priceParts[2]);
                    ourPrice = decimal.Parse(priceParts[3]); //decimal.Parse(spanOurPrice.InnerText, System.Globalization.NumberStyles.Currency);
                }
                catch { }

                var divIsSoldOut = GetElement(all, "DIV", "id", "issoldout");
                var isSoldOut = divIsSoldOut != null && divIsSoldOut.Style.ToLower() == "display:none";

                var aMoreInfo = GetElement(all, "A", "id", "speclink");
                var moreInfoUri = aMoreInfo.GetAttribute("href");

                var aBuyNow = GetElement(all, "A", "id", "btnbuy");
                var buyNowUri = aBuyNow.GetAttribute("href");

                return new IBoodProduct {
                    Name = prodName,
                    ImageUri = new Uri(prodImage),
                    Status = isSoldOut ? ProductStatus.IsSoldOut : ProductStatus.NotSoldOut,
                    RegularPrice = oldPrice,
                    OurPrice= ourPrice ,
                    ShippingCost = shippingCost,
                    MoreInfoUri = new Uri(moreInfoUri),
                    BuyNowUri = new Uri(buyNowUri)
                };
            }
            catch { }
            return null;
        }
開發者ID:dieterm,項目名稱:IBoodHuntMonitor,代碼行數:56,代碼來源:IBoodProduct.cs

示例11: HtmlDocumentAdapter

        public HtmlDocumentAdapter( HtmlDocument doc )
        {
            if ( doc == null )
            {
                throw new ArgumentNullException( "doc" );
            }

            Document = doc;
            myElementAdapters = new Dictionary<HtmlElement, HtmlElementAdapter>();
        }
開發者ID:bg0jr,項目名稱:Maui,代碼行數:10,代碼來源:HtmlDocumentAdapter.cs

示例12: WebEngine

        public WebEngine(HtmlDocument document, string webRoot)
        {
            _document = document;
            _webRoot = webRoot;

            session = engine.CreateSession(document);
            session.AddReference("System.Windows.Forms");

            RegisterEvents();
            CompileScripts();
        }
開發者ID:ZanderAdam,項目名稱:Roslyn-Web-Scripting,代碼行數:11,代碼來源:WebEngine.cs

示例13: ScrapePage

        public void ScrapePage(HtmlDocument link)
        {
            CurrentDoc = link;

            TableData.Add(CurrentDoc.GetElementById("ctl00_cphBody_repeaterOwnerInformation_ctl00_lblOwnerName").InnerText);
            TableData.Add(CurrentDoc.GetElementById("ctl00_cphBody_lblHeaderPropertyAddress").InnerText);
            ScrapeHTMLTables("buildingsDetailWrapper", "table", 0);
            ScrapeHTMLTables("buildingsDetailWrapper", "table", 1);
            ScrapeHTMLTables("buildingsDetailWrapper", "table", 3);
            RemoveUnneededListElements();
        }
開發者ID:josecerejo,項目名稱:PageScraper,代碼行數:11,代碼來源:COJScraper.cs

示例14: SetFileUpload

        protected void SetFileUpload(HtmlDocument document, string name, string fileName)
        {
            var fileElement = (HTMLInputElement)document.GetElementById(name).DomElement;

            fileElement.focus();

            // The first space is to open the file open dialog. The
            // remainder of the spaces is to have some messages for
            // until the open dialog actually opens.

            SendKeys.SendWait("       " + fileName + "{ENTER}");
        }
開發者ID:smile921,項目名稱:hak_blog,代碼行數:12,代碼來源:WebBrowserFixtureBase.cs

示例15: ExecScript

        public static object ExecScript(HtmlDocument doc, string js)
        {
            object ret = null;
            if (String.IsNullOrEmpty(js) == false)
            {
                mshtml.IHTMLDocument2 d = doc.DomDocument as mshtml.IHTMLDocument2;
                mshtml.IHTMLWindow2 win = d.parentWindow as mshtml.IHTMLWindow2;
                ret = win.execScript(js, "javascript");

            }

            return ret;
        }
開發者ID:kener1985,項目名稱:MyGitHubProj,代碼行數:13,代碼來源:ScriptUtility.cs


注:本文中的System.Windows.Forms.HtmlDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。