本文整理汇总了C#中System.Windows.Forms.HtmlDocument.GetElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.GetElementsByTagName方法的具体用法?C# HtmlDocument.GetElementsByTagName怎么用?C# HtmlDocument.GetElementsByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.GetElementsByTagName方法的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 });
}
}
}
}
}
示例2: 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);
}
示例3: 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;
}
示例4: Login
private void Login(string username, string password)
{
doc = webBrowser1.Document;
doc.All["ctl00_ctl17_Username"].SetAttribute("value", username);
doc.All["ctl00_ctl17_Password"].SetAttribute("value", password);
HtmlElementCollection oHtmlElements = doc.GetElementsByTagName("input");
oHtmlElements["ctl00_ctl17_LoginButton"].InvokeMember("click");
}
示例5: GetPostData
private Dictionary<String, String> GetPostData(HtmlDocument doc,string formName, Uri target, Uri baseURL)
{
Dictionary<String, String> ret = new Dictionary<String, String>();
foreach (HtmlElement form in doc.GetElementsByTagName("save_passenger_single"))
if ((form.GetAttribute("mode").ToLower() == "post") && ((target == (new Uri(baseURL, form.GetAttribute("target"))))))
foreach (HtmlElement widget in form.GetElementsByTagName("input"))
{
String name = widget.GetAttribute("name");
if (name != "")
ret.Add(name, widget.GetAttribute("value"));
}
return ret;
}
示例6: getTweetCount
/// <summary>
/// 表示されている自分のツイート数をカウントする
/// 非常に遅いので未使用
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public int getTweetCount(HtmlDocument doc)
{
int count = 0;
string href0 = "";
foreach (HtmlElement el in doc.GetElementsByTagName("a"))
{
string cname = el.GetAttribute("className");
if (cname == "tweet-timestamp js-permalink")
{
string href = el.GetAttribute("href");
if ( href0 != href &&
href.StartsWith("http://twitter.com/#!/" + screenName)== true) {
count++;
href0 = href;
}
}
}
return count;
}
示例7: GetElementByXpath
private HtmlElement GetElementByXpath(HtmlDocument doc, string xpath)
{
if (doc == null) return null;
xpath = xpath.Replace("/html/", "");
HtmlElementCollection eleColec = doc.GetElementsByTagName("html"); if (eleColec.Count == 0) return null;
HtmlElement ele = eleColec[0];
string[] tagList = xpath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string tag in tagList)
{
System.Text.RegularExpressions.Match mat = System.Text.RegularExpressions.Regex.Match(tag, "(?<tag>.+)\\[@id='(?<id>.+)'\\]");
if (mat.Success == true)
{
string id = mat.Groups["id"].Value;
HtmlElement tmpEle = doc.GetElementById(id);
if (tmpEle != null) ele = tmpEle;
else
{
ele = null;
break;
}
}
else
{
mat = System.Text.RegularExpressions.Regex.Match(tag, "(?<tag>.+)\\[(?<ind>[0-9]+)\\]");
if (mat.Success == false)
{
HtmlElement tmpEle = null;
foreach (HtmlElement it in ele.Children)
{
if (it.TagName.ToLower() == tag)
{
tmpEle = it;
break;
}
}
if (tmpEle != null) ele = tmpEle;
else
{
ele = null;
break;
}
}
else
{
string tagName = mat.Groups["tag"].Value;
int ind = int.Parse(mat.Groups["ind"].Value);
int count = 0;
HtmlElement tmpEle = null;
foreach (HtmlElement it in ele.Children)
{
if (it.TagName.ToLower() == tagName)
{
count++;
if (ind == count)
{
tmpEle = it;
break;
}
}
}
if (tmpEle != null) ele = tmpEle;
else
{
ele = null;
break;
}
}
}
}
if (ele != null)
{
if (scrollToViewToolStripMenuItem.Enabled == true)
{
ele.ScrollIntoView(true);
}
else
{
ele.ScrollIntoView(false);
}
if (colorElementToolStripMenuItem.Enabled == true)
{
CheckElement(ele);
}
//ele.Focus();
}
return ele;
}
示例8: mainBrowser_DocumentCompleted
//.........这里部分代码省略.........
/************************************
* 작동하지 않는 서비스 있을시
************************************/
if (doc.GetElementById("urlError").InnerText.Trim() == "true")
{
urlError = true;
bbStartUrl = doc.GetElementById("bbStartUrl").InnerText.Trim();
bbEndUrl = doc.GetElementById("bbEndUrl").InnerText.Trim();
bbAnnounceUrl = doc.GetElementById("bbAnnounceUrl").InnerText.Trim();
libraryStartUrl = doc.GetElementById("libraryStartUrl").InnerText.Trim();
libraryEndUrl = doc.GetElementById("libraryEndUrl").InnerText.Trim();
dormStartUrl = doc.GetElementById("dormStartUrl").InnerText.Trim();
dormEndUrl = doc.GetElementById("dormEndUrl").InnerText.Trim();
mailStartUrl = doc.GetElementById("mailStartUrl").InnerText.Trim();
mailEndUrl = doc.GetElementById("mailEndUrl").InnerText.Trim();
}
/************************************
* 공지사항
************************************/
if (doc.GetElementById("announce").InnerText != null)
{
MessageBox.Show(doc.GetElementById("announce").InnerText, doc.GetElementById("announceTitle").InnerText);
}
if (currentVersion.IndexOf(lastestVersion) != -1)
{
loadingLabel.Text = "최신 버전입니다 :)";
}
else
{
loadingLabel.Text = "최신 버전이 아닙니다 :(";
}
mainBrowser.Navigate("https://portal.unist.ac.kr/EP/web/login/unist_acube_login_int.jsp");
}
/**********************************************************
*
* 로그인 창에서 변수 입력
*
**********************************************************/
loadingProgressBar.Value += 1;
if (e.Url.ToString() == "https://portal.unist.ac.kr/EP/web/login/unist_acube_login_int.jsp")
{
System.Threading.Thread.Sleep(2000);
doc = mainBrowser.Document as HtmlDocument;
doc.GetElementById("id").SetAttribute("value", Program.id);
doc.GetElementsByTagName("input")["UserPassWord"].SetAttribute("value", Program.password);
doc.InvokeScript("doLogin");
/************************************
* 포탈 로그인 단계
************************************/
loadingLabel.Text = "포탈 로그인중";
loadingProgressBar.Value += 5;
}
/**********************************************************
*
* 첫 로그인, 이름 저장, 학사 공지로 이동
*
**********************************************************/
if (e.Url.ToString() == "http://portal.unist.ac.kr/EP/web/portal/jsp/EP_TopFixed.jsp")
{
if (isPortalComplete == false)
{
/************************************
* 포탈 로그인 완료
************************************/
loadingLabel.Text = "포탈 로그인 완료";
loadingProgressBar.Value += 5;
portalCookie = mainBrowser.Document.Cookie;
welcomeLabel.Click += new EventHandler(welcomeLabel_Click);
userName = mainBrowser.DocumentTitle.ToString().Split('-')[1].Split('/')[0];
welcomeLabel.Text = userName + " 님 환영합니다 :^)";
portal = new Portal(portalCookie, this);
showBoardGrid(1);
isPortalComplete = true;
browser.Navigate(bbStartUrl);
}
else
{
browser.Navigate(bbStartUrl);
}
}
}
示例9: DisplayInTree
/// <summary>
/// Called by the thread.start to set up for filling the DOM tree
/// </summary>
/// <param name="elemColl">HTMLElement collection with the "HTML" tag as its root</param>
/// <remarks>Has to be passed as an object for the ParameterizedThreadStart</remarks>
private void DisplayInTree(HtmlDocument docResponse)
{
HtmlElementCollection elemColl = docResponse.GetElementsByTagName("html");
tvDocument.Nodes.Clear();
TreeNode rootNode = new TreeNode("Web response");
rootNode.Tag = -1;
tvDocument.Nodes.Add(rootNode);
FillDomTree(elemColl, rootNode, 0);
}
示例10: getCourceMenu
public void getCourceMenu()
{
// http://bb.unist.ac.kr/webapps/blackboard/content/courseMenu.jsp?course_id=_11194_1&newWindow=true&openInParentWindow=true&refreshCourseMenu=true
for (int i = 0; i < board.Count(); i++)
{
string url = "http://bb.unist.ac.kr/webapps/blackboard/content/courseMenu.jsp?course_id=" + board[i].url;
browser.Navigate(url);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
doc = browser.Document as HtmlDocument;
HtmlElementCollection options = doc.GetElementsByTagName("Option");
HtmlElement elements = ElementsByClass(doc, "courseMenu").ElementAt(0);
HtmlElementCollection lists = elements.GetElementsByTagName("li");
HtmlElementCollection a = elements.GetElementsByTagName("a");
board[i].menu = new List<string>();
board[i].menuUrl = new List<string>();
for (int j = 0; j < lists.Count; j++)
{
board[i].menu.Add(lists[j].InnerText);
board[i].menuUrl.Add(a[j].GetAttribute("href"));
}
}
addCourseMenu();
}
示例11: Getwebpagesource
/// <summary>
/// 將網頁原始碼擷取出來
/// </summary>
/// <param name="HD">轉換網頁的物件</param>
/// <returns>回傳出網頁的原始碼</returns>
public string Getwebpagesource(HtmlDocument HD)
{
JQ(HD);
HtmlElement htmlElement = HD.GetElementsByTagName("HTML")[0];
return htmlElement.InnerHtml;
}
示例12: RetrieveDaily
private bool RetrieveDaily(HtmlDocument doc, MoneyDatabaseUpdater dbUpdater)
{
bool isRetrievedAny = false;
foreach (HtmlElement eleTr in doc.GetElementsByTagName("tr"))
{
DateTime billTime = DateTime.Now;
double amount = 0;
byte changeType = 0;
foreach(HtmlElement eleTd in eleTr.Children)
{
string className = eleTd.GetAttribute("classname");
if (className.Contains("billTime"))
{
try
{
billTime = DateTime.Parse(eleTd.InnerText);
}
catch
{
continue;
}
}
else if (className.Contains("ft-bold"))
{
amount = this.GetAmountFromText(eleTd.InnerText);
}
else if (className.Contains("billAmount"))
{
changeType = this.GetTypeFromText(eleTd.InnerText);
}
}
if (amount != 0)
{
Debug.Assert(changeType != 0, "未知的类型出现了!");
dbUpdater.AddDaily(billTime, amount, changeType);
isRetrievedAny = true;
}
}
return isRetrievedAny;
}
示例13: setBoard
public void setBoard()
{
doc = browser.Document as HtmlDocument;
HtmlElementCollection options = doc.GetElementsByTagName("Option");
int removeCount = 0;
for (int i = 0; i < options.Count; i++)
{
if (options[i].InnerText.IndexOf("Survey") != -1)
removeCount++;
else if (options[i].InnerText.IndexOf("Open Study") != -1)
removeCount++;
else if (options[i].InnerText.IndexOf("Organizations") != -1)
removeCount++;
else if (options[i].InnerText.IndexOf("Show All") != -1)
removeCount++;
else if (options[i].InnerText.IndexOf("Institution Only") != -1)
removeCount++;
else if (options[i].InnerText.IndexOf("Courses Only") != -1)
removeCount++;
else if (options[i].InnerText.IndexOf("UNIST") != -1)
removeCount++;
}
board = new BBBoard[options.Count - removeCount];
int j = 0;
for (int i = 0; i < options.Count; i++)
{
string n = options[i].InnerText.Replace("-", "");
// Open Study 제외
if (n.IndexOf("Open Study") != -1 || n.IndexOf("Organizations") != -1 || n.IndexOf("Survey") != -1 || n.IndexOf("Show All") != -1 || n.IndexOf("Institution Only") != -1 || n.IndexOf("Courses Only") != -1 || n.IndexOf("UNIST") != -1)
{
j++;
continue;
}
board[i - j] = new BBBoard();
board[i - j].url = options[i].OuterHtml.Split('=')[1].Split('>')[0];
board[i - j].name = n;
}
}
示例14: GetTableColumnValueFromHtmlDocument
protected bool GetTableColumnValueFromHtmlDocument(HtmlDocument doc, string dbtable, string dbcolumn, ref object result)
{
foreach (string str in WebBrowserExtensions.tags)
{
HtmlElementCollection elementsByTagName = doc.GetElementsByTagName(str);
foreach (HtmlElement element in elementsByTagName)
{
string attribute = element.GetAttribute("dbtable");
string str3 = element.GetAttribute("dbcolumn");
if (((!string.IsNullOrEmpty(attribute) && !string.IsNullOrEmpty(dbcolumn)) && (attribute == dbtable)) && (str3 == dbcolumn))
{
result = element.GetAttribute("value");
return true;
}
}
}
return false;
}
示例15: Process
public override void Process(HtmlDocument doc)
{
Processed = true;
HtmlElement details = null;
bool hasAddress = false;
bool hasDetails = false;
foreach (HtmlElement div in doc.GetElementsByTagName("div"))
{
String cn = div.GetAttribute("className");
if (cn == "cop_address")
{
Address = div.InnerText;
hasAddress = true;
}
else if (cn == "cop_contact_inf")
{
details = div;
hasDetails = true;
}
if (hasAddress && hasDetails)
break;
}
// process details
foreach (HtmlElement li in details.GetElementsByTagName("li"))
{
String cname = li.FirstChild.GetAttribute("className");
if (cname == "call_i")
{
Phones.Add(li.Children[1].InnerText.Trim());
}
else if (cname == "web_i")
{
Sites.Add(li.Children[1].InnerText.Trim());
}
else
{
MessageBox.Show(Url.ToString() + ": " + cname);
}
}
// coordinates
MatchCollection matches = Regex.Matches(doc.Body.InnerHtml, "google\\.maps\\.LatLng\\((.*?)\\)");
if (matches.Count > 0)
{
Coords = matches[0].Groups[1].Value;
}
}