///// <summary> ///// 填报checkbox数据。 ///// </summary> ///// <param name="value"></param> ///// <param name="checkBoxGroup"></param> //private void FillCheckBoxGroup(string value, Hashtable checkBoxGroup) //{ // string[] values = value == null ? null : value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); // if (values == null) // return; // for (int i = 0; i < values.Length; i++) // { // FillParameter dElement = checkBoxGroup[values[i]] as FillParameter; // if (dElement == null) // continue; // IHTMLInputElement element = base.GetElement(dElement, _formIndex) as IHTMLInputElement; // if (element == null) // continue; // element.@checked = true; // } //} protected override IHTMLElement FindElement(System.Windows.Forms.HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex) { if (string.IsNullOrEmpty(parameter.FindCode) == false) { return(InvokeScriptSync(doc, "findElementByExpr", new object[] { parameter.FindCode }) as IHTMLElement); } else { return(InvokeScriptSync(doc, "findElement", new object[] { elementType, parameter.Id, parameter.Name, parameter.Value, parameter.OnClick, formIndex }) as IHTMLElement); } }
public virtual void NotifyScreenOk(System.Windows.Forms.HtmlDocument argDoc) { Debug.Assert(null != argDoc); if (null != m_listStoryboards) { foreach (var sb in m_listStoryboards) { sb.NotifyScreenOk(argDoc); } } }
private void web_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { //web.Navigate("javascript: window.external.CallServerSideCode();"); mshtml.IHTMLDocument2 htmlDocument = web.Document.DomDocument as mshtml.IHTMLDocument2; htmlDocument2 = htmlDocument; //web.D //richTextBox1.AppendText(htmlDocument.body.parentElement.outerHTML); this.document = this.web.Document; this.document.MouseDown += new System.Windows.Forms.HtmlElementEventHandler(document_MouseDown); this.document.MouseOver += new System.Windows.Forms.HtmlElementEventHandler(document_MouseOver); this.document.MouseLeave += new System.Windows.Forms.HtmlElementEventHandler(document_MouseLeave); }
protected override mshtml.IHTMLElement FindElement(System.Windows.Forms.HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex) { if (string.IsNullOrEmpty(parameter.SearchType)) { return(InvokeScriptSync(doc, "findElement", new object[] { elementType, parameter.Name, parameter.Value, parameter.OnClick, parameter.ReturnIndex }) as mshtml.IHTMLElement); } else { string filter = string.Format(parameter.SearchType, parameter.ParameterName == null ? null : string.Format("\"{0}\"", base.DataTable[parameter.ParameterName])); return(InvokeScriptSync(doc, "findElementByFilter", new object[] { filter, parameter.ReturnIndex }) as mshtml.IHTMLElement); } }
private void web_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { mshtml.IHTMLDocument2 htmlDocument = automation_browser.Document.DomDocument as mshtml.IHTMLDocument2; htmlDocument2 = htmlDocument; this.document = this.automation_browser.Document; this.document.MouseDown += new System.Windows.Forms.HtmlElementEventHandler(document_MouseDown); //this.document.MouseOver += new System.Windows.Forms.HtmlElementEventHandler(document_MouseOver); //this.document.MouseLeave += new System.Windows.Forms.HtmlElementEventHandler(document_MouseLeave); }
private void AddEventHandlesOfHtmlDocument(System.Windows.Forms.HtmlDocument doc) { if (null == doc) { return; } Debug.Assert(null != doc); // doc.Click += m_clickHandler; doc.MouseDown += m_mouseDownHandler; doc.ContextMenuShowing += m_contextMenuHandler; doc.MouseUp += m_mouseUpHandler; }
public void NotifyScreenOk(System.Windows.Forms.HtmlDocument argDoc) { Debug.Assert(null != argDoc); if (!string.IsNullOrEmpty(m_targetName)) { m_targetElement = argDoc.GetElementById(m_targetName); } foreach (var timeline in m_listTimelines) { timeline.NotifyScreenOk(argDoc); } }
private void WebBrowser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { System.Windows.Forms.HtmlDocument html = this._webBrowser.Document; LayoutContent content = this._holder as LayoutContent; if (content != null && html != null) { if (!String.IsNullOrEmpty(html.Title)) { content.Title = html.Title; } else { content.Title = "untitled"; } } }
private void OnLeftButtonDown(object sender, System.Windows.Forms.HtmlElementEventArgs arg) { System.Windows.Forms.HtmlDocument doc = (System.Windows.Forms.HtmlDocument)sender; System.Windows.Forms.HtmlElement element = doc.GetElementFromPoint(arg.MousePosition); HtmlScreenElementBase newFcsElement = FindFocusElement(element); if (null != newFcsElement) { if (m_focusElement != newFcsElement) { m_focusElement = newFcsElement; // ShowHandleInput(true); } m_focusElement.SetFocus(); } else { ShowScreenKeyboard(false); m_focusElement = null; // ShowHandleInput(false); } HtmlScreenElementBase button = FindButtonInHtml(element); if (null == button) { System.Windows.Forms.HtmlElement parentElement = element.Parent; if (null == parentElement) { return; } button = FindButtonInHtml(parentElement); if (null == button) { return; } } button.OnLeftMouseDown(sender, arg); arg.ReturnValue = true; }
private string[] SearchWebPage() { if (wb1.Document == null) { return(null); } System.Windows.Forms.HtmlElementCollection elemColl = null; System.Windows.Forms.HtmlDocument doc = wb1.Document; if (doc != null) { AddTextStr("--- Start ---"); } string strText = ""; foreach (System.Windows.Forms.HtmlElement elem in elemColl) { if (elem.InnerHtml.Contains("row quotebox")) { strText = elem.InnerText; strText = Regex.Replace(strText, "[\x00-\x1F]+", "/"); string[] strarr = strText.Split('/'); Console.WriteLine("In 'row quotebox' Children: {0,2} elem.InnerHtml.Length: {1,5}", elem.Children.Count, elem.InnerHtml.Length); int nn = 0; foreach (string split in strarr) { if (split.StartsWith("Kurs")) { Console.WriteLine("{0,3} split:{1}", ++nn, split); AddTextStr(split); } } Console.WriteLine("---------------------------------------------------------------"); return(strarr); } // end if } // foreach HtmlElement return(null); // Wenn kein 'row quotebox' gefunden. }
public IQuotation Parse(System.Windows.Forms.HtmlDocument wbHtmlDoc) { Quotation q = new Quotation(); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(wbHtmlDoc.Body.OuterHtml); // find select text span of quantity var nodes = htmlDoc.DocumentNode.SelectNodes("//span[contains(@class,'current')]"); if (nodes == null) { throw new Exception("Can't find text span of quantity."); } foreach (var quantitySpanNode in nodes) { string quantityText = quantitySpanNode.InnerText.Trim(); // if there is not quantity text, notstock int qry; if (!int.TryParse(quantityText, out qry)) { continue; } // if (string.IsNullOrWhiteSpace((quantityText))) continue; // get parent of name / price ... var parentDiv = quantitySpanNode.SelectSingleNode("../../.."); // get prod name var prodNameAnchor = parentDiv.SelectSingleNode(".//div[contains(@class, 'prod_name_choose')]/a"); if (null == prodNameAnchor) { throw new Exception("Can't find prod name anchor."); } string prodName = prodNameAnchor.InnerText.Trim(); // get diy price var diyPriceDiv = parentDiv.SelectSingleNode(".//div[contains(@class, 'diy_price')]"); if (null == diyPriceDiv) { throw new Exception("Can't find diy price div."); } string diyPrice = diyPriceDiv.InnerText.Trim(); q.Items.Add(new QuotationItem() { Name = prodName, Quantity = quantityText, TotalAmount = diyPrice, }); } var totalPriceSpan = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='subtotal']"); if (null != totalPriceSpan) { q.TotalAmount = totalPriceSpan.InnerText.Trim(); } return(q); }
internal HtmlDocument(System.Windows.Forms.HtmlDocument htmlDocument) { sysWinFormHtmlDoc = htmlDocument; msHtmlDocInterface = (mshtml.IHTMLDocument2)htmlDocument.DomDocument; }
////填充参数 //protected void FillElement(FillParameter parameter, string value) //{ // if (parameter == null) // return; // IHTMLElement element = null; // if (parameter.Type != Matcher.TYPE_FORM) // { // string key = parameter.FrameId; // if (string.IsNullOrEmpty(key)) // key = "@"; // //查找元素,如果是null就是代表没有此元素 // element = base.GetElement(parameter, formIndexes[key]); // if (element == null) // { // base.FillRecords.Add(new FillRecord(GetElementType(parameter.Type), RecordType.Failed, "未找到此元素", parameter.ParameterName)); // return; // } // if (parameter.Type == Matcher.TYPE_FILE) // { // if (string.IsNullOrEmpty(value)) // return; // value = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value); // if (System.IO.File.Exists(value) == false) // { // base.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", value), parameter.ParameterName)); // return; // } // } // ((IHTMLElement2)element).focus(); // } // _currentFillValue = value; // switch (parameter.Type) // { // case Matcher.TYPE_FORM: // string key = parameter.FrameId; // if (string.IsNullOrEmpty(key)) // key = "@"; // if (formIndexes.ContainsKey(key)) // formIndexes[key] = formIndexes[key] + 1; // else // formIndexes[key] = 0; // break; // case Matcher.TYPE_RADIO: // IHTMLInputElement radioElement = element as IHTMLInputElement; // radioElement.@checked = true; // base.FillRecords[(int)ElementType.Radio].RecordCount++; // break; // case Matcher.TYPE_SELECT: // IHTMLSelectElement selectElement = element as IHTMLSelectElement; // if (FillSelectElement(selectElement, value)) // base.FillRecords[(int)ElementType.Select].RecordCount++; // else // base.FillRecords.Add(new FillRecord(ElementType.Select, RecordType.Failed, string.Format("下拉框中不包含选项 {0}", value), parameter.ParameterName)); // break; // case Matcher.TYPE_A: // element.click(); // break; // case Matcher.TYPE_FILE: // element.click(); // base.FillRecords[(int)ElementType.File].RecordCount++; // break; // case Matcher.TYPE_SUBMIT: // case Matcher.TYPE_BUTTON: // case "BUTTON/SUBMIT": // IHTMLInputElement fileElement = element as IHTMLInputElement; // element.click(); // break; // case Matcher.TYPE_TEXTAREA: // IHTMLTextAreaElement textAreaElement = element as IHTMLTextAreaElement; // textAreaElement.value = value; // base.FillRecords[(int)ElementType.Text].RecordCount++; // break; // case Matcher.TYPE_TEXT: // case Matcher.TYPE_PASSWORD: // IHTMLInputElement textElement = element as IHTMLInputElement; // textElement.value = value; // base.FillRecords[(int)ElementType.Text].RecordCount++; // break; // } //} //private void FillElement(FillParameterKey parameterKey, object elementContainer, string parameterValue) //{ // this.Wait(); // FillParameter fillParameter = elementContainer as FillParameter; // if (fillParameter == null) // { // Hashtable table = elementContainer as Hashtable; // if (table == null) // return; // else if (parameterKey.Type == Matcher.TYPE_RADIO) // { // // 处理radio类型的选择 // if (parameterValue != null) // { // if (table.ContainsKey(parameterValue) == false) // base.FillRecords.Add(new FillRecord(ElementType.Radio, RecordType.Failed, string.Format("单选框中不包含项 {0}", parameterValue), parameterKey.Key)); // fillParameter = table[parameterValue] as FillParameter; // } // } // else if (parameterKey.Type == Matcher.TYPE_CHECKBOX) // 处理checkBox类型 // { // FillCheckBoxGroup(parameterValue, parameterKey.Key, table); // return; // } // } // FillElement(fillParameter, parameterValue); //} protected override IHTMLElement FindElement(System.Windows.Forms.HtmlDocument doc, FillParameter parameter, bool isContain, string elementType, int formIndex) { return(InvokeScriptSync(doc, "findElement", new object[] { elementType, parameter.Id, parameter.Name, parameter.Value, parameter.OnClick, formIndex }) as IHTMLElement); }
// get stock latest quote public Quote GetQuote(string ticker) { XmlDocument xml = null; System.Windows.Forms.HtmlElement elem = null; // correct symbol SymbolSet.SymbolTableRow tck = CorrectSymbolRow(ticker); if (tck == null) { return(null); } // is index ? bool is_index = tck.Symbol.StartsWith("^"); // clear global cache cache_dict.Clear(); XmlNode nd, row_nd = null; System.Windows.Forms.HtmlDocument doc = null; // @"http://www.nasdaqomxnordic.com/shares/optionsandfutures/?Instrument={0}" // @"http://www.nasdaqomxnordic.com/optionsandfutures/microsite?Instrument={0}" // get url to quote+option-chain page string url = string.Format(@"http://www.nasdaqomxnordic.com/shares/optionsandfutures/?Instrument={0}", is_index ? tck.Isin : tck.Id); // read first page (try twice before giving up) doc = wbf.GetHtmlDocumentWithWebBrowser(url, null, "optionsAndFuturesTable", "TABLE", 60); if (doc == null || doc.Body == null || string.IsNullOrEmpty(doc.Body.InnerText)) { return(null); } // get quote table elem = doc.GetElementById("avistaTable"); if (elem == null) { return(null); } xml = cap.ConvertHtmlToXml(elem.OuterHtml); if (xml == null) { return(null); } row_nd = prs.GetXmlNodeByPath(xml.FirstChild, @"TBODY\TR"); if (row_nd == null) { return(null); } // create quote Quote quote = new Quote(); // get stock symbol / name quote.stock = tck.Symbol; // get name quote.name = quote.stock; nd = prs.GetXmlNodeByPath(row_nd, @"TD(1)"); if (nd != null && nd.InnerText != "") { try { quote.name = nd.InnerText.Trim(); } catch { } } // get last price quote.price.last = double.NaN; nd = prs.GetXmlNodeByPath(row_nd, @"TD(2)"); if (nd != null && nd.InnerText != "") { try { quote.price.last = Convert.ToDouble(nd.InnerText); } catch { } } // get price change quote.price.change = double.NaN; nd = prs.GetXmlNodeByPath(row_nd, @"TD(3)"); if (nd != null && nd.InnerText != "") { try { quote.price.change = Convert.ToDouble(nd.InnerText); } catch { } } // get open price quote.price.open = quote.price.last - quote.price.change; // get bid price quote.price.bid = double.NaN; nd = prs.GetXmlNodeByPath(row_nd, @"TD(5)"); if (nd != null && nd.InnerText != "") { try { quote.price.bid = Convert.ToDouble(nd.InnerText); } catch { } } // get ask price quote.price.ask = double.NaN; nd = prs.GetXmlNodeByPath(row_nd, @"TD(6)"); if (nd != null && nd.InnerText != "") { try { quote.price.ask = Convert.ToDouble(nd.InnerText); } catch { } } // get high price quote.price.high = double.NaN; nd = prs.GetXmlNodeByPath(row_nd, @"TD(7)"); if (nd != null && nd.InnerText != "") { try { quote.price.high = Convert.ToDouble(nd.InnerText); } catch { } } // get low price quote.price.low = double.NaN; nd = prs.GetXmlNodeByPath(row_nd, @"TD(8)"); if (nd != null && nd.InnerText != "") { try { quote.price.low = Convert.ToDouble(nd.InnerText); } catch { } } // get total volume quote.volume.total = double.NaN; elem = doc.GetElementById("tradingInformationTable"); if (elem != null) { xml = cap.ConvertHtmlToXml(elem.OuterHtml); if (xml != null) { nd = prs.GetXmlNodeByPath(xml.FirstChild, @"TBODY\TR(3)\TD(2)"); if (nd != null && nd.InnerText != "") { try { quote.volume.total = Convert.ToDouble(nd.InnerText) * quote.price.last; } catch { } } } } // time-stamp quote.update_timestamp = DateTime.Now; // get and cache option table elem = doc.GetElementById("optionsAndFuturesTable"); if (elem != null) { xml = cap.ConvertHtmlToXml(elem.OuterHtml); if (xml != null) { cache_dict.Add(tck.Id, xml); } } return(quote); }
//private void FindAllButtonsInHtml( System.Windows.Forms.HtmlDocument doc ) //{ // Debug.Assert(null != doc); // System.Windows.Forms.HtmlElement body = doc.Body; // if ( null == body ) // { // return; // } // m_listButtons.Clear(); // System.Windows.Forms.HtmlElementCollection elementCollection = body.All; // Debug.Assert(null != elementCollection); // string valueOfAttri = null; // foreach ( System.Windows.Forms.HtmlElement element in elementCollection ) // { // valueOfAttri = element.GetAttribute(s_typeAttri); // if ( string.IsNullOrEmpty (valueOfAttri) ) // { // continue; // } // if ( 0 == string.Compare( valueOfAttri, s_buttonValue, true ) ) // { // m_listButtons.Add(element); // } // } //} private void ExtractAllScreenElements(System.Windows.Forms.HtmlDocument argDoc) { Debug.Assert(null != argDoc); System.Windows.Forms.HtmlElement body = argDoc.Body; if (null == body) { return; } m_listBindingExpresses.Clear(); ClearScreenElements(); System.Windows.Forms.HtmlElementCollection elementCollection = body.All; Debug.Assert(null != elementCollection); HtmlScreenElementBase screenElement = null; string idsValue = null; string valueOfAttri = null; IResourceService iCurrentUIResource = null; if (null != m_application.ResourceManager) { iCurrentUIResource = m_application.ResourceManager.CurrentUIResource; } string text = null; string replaceAttri = null; int replaceValue = 0; string imagePath = null; string srcPath = null; foreach (System.Windows.Forms.HtmlElement element in elementCollection) { //replace ids idsValue = element.GetAttribute(s_UITextKey); if (null != iCurrentUIResource && !string.IsNullOrEmpty(idsValue)) { if (iCurrentUIResource.LoadString(idsValue, TextCategory.s_UI, out text)) { element.InnerHtml = ConvertText(text); } } //replace image if (null != iCurrentUIResource && s_imgName.Equals(element.TagName, StringComparison.OrdinalIgnoreCase)) { replaceAttri = element.GetAttribute(s_replaceAttri); srcPath = element.GetAttribute("src"); if (!string.IsNullOrEmpty(replaceAttri) && !string.IsNullOrEmpty(srcPath) && int.TryParse(replaceAttri, out replaceValue) && replaceValue == 1) { if (iCurrentUIResource.QueryImagePath(srcPath, out imagePath)) { element.SetAttribute("src", imagePath); } } } if (string.IsNullOrEmpty(element.Id)) { continue; } valueOfAttri = element.GetAttribute(s_typeAttri); if (string.IsNullOrEmpty(valueOfAttri)) { continue; } valueOfAttri = valueOfAttri.ToLowerInvariant(); if (m_dicScreenElementCreator.ContainsKey(valueOfAttri)) { try { screenElement = m_dicScreenElementCreator[valueOfAttri].Invoke(element); if (null != screenElement) { m_dicScreenElements.Add(element.Id.ToLowerInvariant(), screenElement); } } catch (System.Exception ex) { LogProcessorService.Log.UIService.LogWarn(string.Format("Failed to create a screen element[{0}]", element.Id), ex); } } } }
// get stock latest options chain public ArrayList GetOptionsChain(string ticker) { XmlDocument xml = null; System.Windows.Forms.HtmlElement elem = null; // correct symbol SymbolSet.SymbolTableRow tck = CorrectSymbolRow(ticker); if (tck == null) { return(null); } // check cache for option data if (!cache_dict.ContainsKey(tck.Id)) { // get url for quote page string url = @"http://www.nasdaqomxnordic.com/shares/optionsandfutures/?Instrument=" + tck.Id; // read first page (try twice before giving up) System.Windows.Forms.HtmlDocument doc = wbf.GetHtmlDocumentWithWebBrowser(url, null, "optionsAndFuturesTable", "TABLE", 30); if (doc == null || doc.Body == null || string.IsNullOrEmpty(doc.Body.InnerText)) { return(null); } elem = doc.GetElementById("optionsAndFuturesTable"); if (elem == null) { return(null); } xml = cap.ConvertHtmlToXml(elem.OuterHtml); } else { xml = cache_dict[tck.Id]; } if (xml == null) { return(null); } // create options array list ArrayList options_list = new ArrayList(); options_list.Clear(); for (int i = 1; ; i++) { XmlNode nd, row_nd = prs.GetXmlNodeByPath(xml.FirstChild, @"TBODY\TR(" + i.ToString() + ")"); if (row_nd == null) { break; } try { // get title string title = null; foreach (XmlAttribute attr in row_nd.Attributes) { if (attr.Name.ToUpper() == "TITLE") { title = attr.Value; break; } } if (title == null) { continue; } string[] split = title.Split('-'); if (split.Length == 1 || (!split[1].Contains("CALL OPTION") && !split[1].Contains("PUT OPTION"))) { continue; } Option option = new Option(); // set option stock option.stock = tck.Symbol; // set option symbol option.symbol = "." + split[0].Trim(); // get option type by parsing the option symbol string stmp = option.symbol.TrimEnd(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }).ToUpper(); char ctmp = stmp[stmp.Length - 1]; if (ctmp >= 'A' && ctmp <= 'L') { option.type = "Call"; } else if (ctmp >= 'M' && ctmp <= 'X') { option.type = "Put"; } else { continue; } // get expiration date nd = prs.GetXmlNodeByPath(row_nd, @"TD(2)"); if (nd == null || nd.InnerText.Trim() == "") { continue; } split = nd.InnerText.Trim().Split(new char[] { '.', '-' }); option.expiration = Convert.ToDateTime(split[1] + "/" + split[2] + "/" + split[0], ci).AddDays(1); // get strike price nd = prs.GetXmlNodeByPath(row_nd, @"TD(11)"); if (nd == null || nd.InnerText.Trim() == "") { continue; } option.strike = Convert.ToDouble(nd.InnerText); // get stocks per contract nd = prs.GetXmlNodeByPath(row_nd, @"TD(10)"); try { option.stocks_per_contract = (int)Convert.ToDecimal(nd.InnerText); } catch { option.stocks_per_contract = 100; } // get bid price nd = prs.GetXmlNodeByPath(row_nd, @"TD(3)"); if (nd == null || nd.InnerText == "") { option.price.bid = double.NaN; } else { try { option.price.bid = Convert.ToDouble(nd.InnerText); } catch { option.price.bid = double.NaN; } } // get ask price nd = prs.GetXmlNodeByPath(row_nd, @"TD(4)"); if (nd == null || nd.InnerText == "") { option.price.ask = double.NaN; } else { try { option.price.ask = Convert.ToDouble(nd.InnerText); } catch { option.price.ask = double.NaN; } } // get last price nd = prs.GetXmlNodeByPath(row_nd, @"TD(5)"); if (nd == null || nd.InnerText == "") { option.price.last = double.NaN; } else { try { option.price.last = Convert.ToDouble(nd.InnerText); } catch { option.price.last = double.NaN; } } // set price change option.price.change = double.NaN; // get option open-int nd = prs.GetXmlNodeByPath(row_nd, @"TD(8)"); if (nd == null || nd.InnerText == "") { option.open_int = 0; } else { try { option.open_int = (int)Convert.ToDecimal(nd.InnerText); } catch { option.open_int = 0; } } // get option volume nd = prs.GetXmlNodeByPath(row_nd, @"TD(9)"); if (nd == null || nd.InnerText == "") { option.volume.total = 0; } else { try { option.volume.total = (int)Convert.ToDecimal(nd.InnerText); } catch { option.volume.total = 0; } } // update time stamp option.update_timestamp = DateTime.Now; // add option to list options_list.Add(option); } catch { } } return(options_list); }