public static bool existElement(object doc, string tag, out string outVal) { bool isIE = doc is HtmlDocument; string[] arr = tag.Split('|'); //p|class|lkjlfd string tagName = arr[0]; //tag p ,a,table ,td,div string tagKeyType = ""; //class ,id,name string tagKeyValue = ""; // if (arr.Length > 1) { tagKeyType = arr[1]; } if (arr.Length > 2) { tagKeyValue = tag.Substring(tagName.Length + 1 + tagKeyType.Length + 1);//除去 tag 和 约束[id|name]的值 } if (isIE) { HtmlElementCollection hec = (doc as HtmlDocument).GetElementsByTagName(tagName); foreach (HtmlElement he in hec) { string idval = null; idval = he.GetAttribute(tagKeyType.Trim()); if (string.IsNullOrEmpty(idval)) //标签都没有 { continue; } if (idval?.Trim().ToLower() == tagKeyValue.ToLower())//如果匹配上了 { outVal = he.InnerText; return(true); } } outVal = null; return(false); } else { GeckoElementCollection hec = (doc as GeckoDocument).GetElementsByTagName(tagName); foreach (GeckoElement he in hec) { string idval = null; idval = he.GetAttribute(tagKeyType.Trim()); if (string.IsNullOrEmpty(idval)) //标签都没有 { continue; } if (idval?.Trim() == tagKeyValue)//如果匹配上了 { outVal = he.TextContent; return(true); } } outVal = null; return(false); } }
private void clickLinkTimer_Tick(object sender, EventArgs e) { //clickLinkTimer.Stop(); Timer timer = (Timer)sender; timer.Stop(); Random rd = new Random(); if (countClickOnSite <= clickLimit) { GeckoElementCollection cv = geckoBrower.Document.GetElementsByTagName("a"); string[] arrInterval = objAdwordConfig.IntervalClick.Split(','); int rdFrom = -1; int rdTo = -1; if (arrInterval.Length > 0) { rdFrom = int.Parse(arrInterval[0]); rdTo = int.Parse(arrInterval[1]); } if (cv != null && cv.Length > 0) { int randomClick = rd.Next(0, cv.Length - 1); if (!StripHTML(cv[randomClick].InnerHtml).Equals("Xem hướng nhà theo tuổi") && !String.IsNullOrEmpty(StripHTML(cv[randomClick].InnerHtml)) && cv[randomClick].GetAttribute("href") != null && cv[randomClick].GetAttribute("href").IndexOf("google.com") == -1) { string strHref = cv[randomClick].GetAttribute("href"); if (strHref.IndexOf("javascript") == -1 && strHref.IndexOf("facebook.com") == -1 && strHref.IndexOf("twitter") == -1 && strHref.IndexOf("maylammatvn.com") == -1 && strHref.IndexOf("plus.google.com") == -1 && strHref.IndexOf("quatlammatvn") == -1 && strHref.IndexOf("duongquoccuongbds.com") == -1) { WriteLog(strHref); cv[randomClick].Click(); // MessageBox.Show(countClickOnSite.ToString()); countClickOnSite = countClickOnSite + 1; } } } else { //MessageBox.Show("href : " + geckoBrower.Url.ToString()); WriteLog("Khong co the a : " + geckoBrower.Url.ToString()); } timer.Interval = (1 * rd.Next(rdFrom, rdTo) * 1000); timer.Start(); } else { // MessageBox.Show("Số lần click on site " + countClickOnSite.ToString()); viewNextURL(); ViewLink(); } }
private void button1_Click(object sender, EventArgs e) { GeckoElementCollection cv = geckoBrower.Document.GetElementsByTagName("a"); foreach (var item in cv) { WriteLog(StripHTML(item.InnerHtml)); string strHref = item.GetAttribute("href"); WriteLog(strHref); } MessageBox.Show("Done"); }
private void tm_XoaNoiDung_Tick(object sender, EventArgs e) { //xóa header GeckoHtmlElement nodeHeader = (Gecko.GeckoHtmlElement)web.Document.SelectSingle("//div[@id='header']"); if (nodeHeader != null) { nodeHeader.ParentNode.RemoveChild(nodeHeader); } //ẩn button soạn tin nhắn và khung tìm kiếm GeckoHtmlElement nodeButton = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//a[@data-sigil='touchable dialog-link']"); if (nodeButton != null) { nodeButton.ParentElement.ParentElement.SetAttribute("style", "display:none;"); } //ẩn các link folder tin nhắn GeckoHtmlElement nodeLink = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//div[@id='threadlist_rows']"); if (nodeLink != null) { ((Gecko.GeckoHtmlElement)nodeLink.NextSibling).SetAttribute("style", "display:none;"); } //ẩn button share GeckoHtmlElement nodeButton2 = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//select[@class='selectBtn touchable']"); if (nodeButton2 != null) { nodeButton2.ParentElement.SetAttribute("style", "display:none;"); } //ẩn khung nhập nội dung form GeckoHtmlElement nodeForm = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//textarea"); if (nodeForm != null) { nodeForm.ParentElement.ParentElement.SetAttribute("style", "display:none;"); } //vô hiệu hóa link vào profile trong hộp chat GeckoElementCollection arrA = web.Document.GetElementsByTagName("a"); foreach (GeckoElement a in arrA) { if (a.GetAttribute("class") == "actor-link") { a.SetAttribute("href", "#"); } } }
//private void clickAdsenTimer_Tick(object sender, EventArgs e) //{ // //Loop khi reset IP // string[] arrLog = File.ReadAllLines(excutePath + @"\Log\ResetIPFlag.txt"); // if (arrLog.Length > 0 && arrLog[arrLog.Length-1].Equals("NewIP")) // { // System.Threading.Thread.Sleep(3 * 60000); // IPPublic = getPublicIP(); // WriteLog(IPPublic.ToString()); // if (!IPPublic.Equals(IPPublic.ToString())) // { // MessageBox.Show(IPPublic); // } // numberURL = 0; // nsIBrowserHistory historyMan = Xpcom.GetService<nsIBrowserHistory>(Gecko.Contracts.NavHistoryService); // historyMan = Xpcom.QueryInterface<nsIBrowserHistory>(historyMan); // historyMan.RemoveAllPages(); // //clear cache // nsICookieManager CookieMan; // CookieMan = Xpcom.GetService<nsICookieManager>("@mozilla.org/cookiemanager;1"); // CookieMan = Xpcom.QueryInterface<nsICookieManager>(CookieMan); // CookieMan.RemoveAll(); // loop_ViewLinkWithIP(); // } //} private void geckoBrower_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e) { if (!isFindingURL) { if (geckoBrower.Url.Host.Equals("www.google.com") || geckoBrower.Url.Host.Equals("www.google.co.uk") || geckoBrower.Url.Host.Equals("www.google.co.jp") || geckoBrower.Url.Host.Equals("www.google.nl") || geckoBrower.Url.Host.Equals("www.google.de")) { GeckoElementCollection cv = geckoBrower.Document.GetElementsByTagName("a"); foreach (var item in cv) { //Doanh nghiệp xanh - Diễn đàn cộng đồng doanh nghiệp Việt Nam if (StripHTML(item.InnerHtml).Equals(objAdwordConfig.TextLink)) { isFindingURL = true; System.Threading.Thread.Sleep(20000); WriteLog(StripHTML(item.InnerHtml)); item.Click(); //Tim thay URL can view thi goi timer de click tren trang clickLinkTimer = new Timer(); clickLinkTimer.Interval = (1 * 20 * 1000); clickLinkTimer.Tick += new EventHandler(clickLinkTimer_Tick); clickLinkTimer.Start(); break; } } if (cv.Length > 0 && !isFindingURL) { page = page + 1; string googleUri = geckoBrower.Url.ToString(); int paraStart = 10 * page; //System.Threading.Thread.Sleep(10000); geckoBrower.Navigate(googleUri + "&start=" + paraStart.ToString()); } } } }
public void Wpbarkodvemesaj() { int gecerliiii = 0; int gecersizzz = 0; islemisonlandir = false; geckoWebBrowser1.Navigate("https://web.whatsapp.com/"); Application.DoEvents(); sondurum.Text = "Telefonunuzun internet bağlatısını kontrol edin ve hazırlanın."; Wpkontroll(); Application.DoEvents(); Application.DoEvents(); LDB.sqlcalistir("INSERT INTO tbl_islemler (grupid,mesajid,siradaki) VALUES(" + selectgrupid + ", " + selectmesajid + "," + aktifkisisayisi + " ) "); Application.DoEvents(); islemidsii = LDB.sorgula("SELECT id FROM tbl_islemler where grupid=" + selectgrupid + " and mesajid=" + selectmesajid + " and siradaki=" + aktifkisisayisi + " ORDER BY id DESC LIMIT 1"); Application.DoEvents(); Application.DoEvents(); siradakinumaralabel.Text = Convert.ToInt32(Convert.ToInt32(aktifkisisayisi) - (gecerliiii + gecersizzz)).ToString(); gecerlileti.Text = "0"; Application.DoEvents(); foreach (DataGridViewRow rowp in dataGridView1.Rows) { Application.DoEvents(); if (rowp.Cells[5].Value.ToString() == "1") { Wpkontroll(); Application.DoEvents(); geckoWebBrowser1.Navigate("https://web.whatsapp.com/send?phone=+" + rowp.Cells[3].Value.ToString().Trim() + "&text=" + selectmesaj); Application.DoEvents(); islemloglabel.Text = rowp.Cells[3].Value.ToString().Trim() + " numarasına mesaj atmayı deniyor"; Application.DoEvents(); Wpkontroll(); Application.DoEvents(); try { Application.DoEvents(); geckoWebBrowser1.Document.GetElementsByClassName("popup-contents")[0].LastChild.ToString(); Application.DoEvents(); gecersizzz++; gecersizileti.Text = gecersizzz.ToString(); siradakinumaralabel.Text = Convert.ToInt32(Convert.ToInt32(aktifkisisayisi) - (gecerliiii + gecersizzz)).ToString(); Application.DoEvents(); LDB.sqlcalistir("INSERT INTO tbl_log (islemid,numaraid,durum) VALUES(" + islemidsii + ", " + rowp.Cells[0].Value.ToString().Trim() + ", 'başarısız' ) "); Application.DoEvents(); } catch { try { Application.DoEvents(); GeckoElementCollection tagsCollection = geckoWebBrowser1.Document.GetElementsByTagName("button"); foreach (GeckoElement currentTag in tagsCollection) { if (currentTag.GetAttribute("class").Equals("_2lkdt")) { Application.DoEvents(); ((GeckoHtmlElement)currentTag).Click(); Application.DoEvents(); ((GeckoHtmlElement)currentTag).Click(); gecerliiii++; siradakinumaralabel.Text = Convert.ToInt32(Convert.ToInt32(aktifkisisayisi) - (gecerliiii + gecersizzz)).ToString(); gecerlileti.Text = gecerliiii.ToString(); Application.DoEvents(); LDB.sqlcalistir("INSERT INTO tbl_log (islemid,numaraid,durum) VALUES(" + islemidsii + ", " + rowp.Cells[0].Value.ToString().Trim() + ", 'başarılı') "); Application.DoEvents(); Thread.Sleep(3000); Application.DoEvents(); } } Application.DoEvents(); } catch { } } Application.DoEvents(); LDB.sqlcalistir("Update tbl_islemler set siradaki=" + siradakinumaralabel.Text.ToString().Trim() + ", basarisiz=" + gecersizileti.Text.ToString().Trim() + ", basarili=" + gecerlileti.Text.ToString().Trim() + " where id=" + islemidsii); Application.DoEvents(); } } MessageBox.Show(gecerlileti.Text.ToString().Trim() + " başarılı mesaj atıldı", "Tebrikler İşlem Tamamlandı"); islemloglabel.Text = ""; Gizle(); RAPORLAR.Visible = true; }
private void Wpkontroll() { bool ooooooo = true; Application.DoEvents(); panelbarkodkenari.Visible = false; Application.DoEvents(); while (ooooooo) { Application.DoEvents(); if (islemisonlandir == true) { return; } Application.DoEvents(); while (DnsTest()) { Application.DoEvents(); } while (Yukleniyor()) { Application.DoEvents(); } Application.DoEvents(); System.Threading.Thread.Sleep(200); try { Application.DoEvents(); GeckoElementCollection tagsCollection = geckoWebBrowser1.Document.GetElementsByTagName("img"); Application.DoEvents(); foreach (GeckoElement currentTag in tagsCollection) { Application.DoEvents(); if (currentTag.GetAttribute("alt").Equals("Scan me!")) { string srcsi = currentTag.GetAttribute("src").ToString(); srcsi = srcsi.Substring(22); pictureBoxbarkod.Image = Base64ToImage(srcsi); Application.DoEvents(); panelbarkodkenari.Visible = true; Application.DoEvents(); sondurum.Text = "Web Whatsapp barkodunu telefonunuzdan okutmanız gerekiyor"; Application.DoEvents(); barkoduokutpnl.Visible = true; Application.DoEvents(); gonderimlerbaslatildipanel.Visible = false; Application.DoEvents(); } } } catch { Application.DoEvents(); panelbarkodkenari.Visible = false; Application.DoEvents(); try { Application.DoEvents(); geckoWebBrowser1.Document.GetElementById("side").ToString(); Gizle(); gonderimlerbaslatildipanel.Visible = true; Application.DoEvents(); ooooooo = false; Application.DoEvents(); } catch { Application.DoEvents(); ooooooo = true; Application.DoEvents(); } Application.DoEvents(); } Application.DoEvents(); } Application.DoEvents(); System.Threading.Thread.Sleep(1000); Application.DoEvents(); }
private void button_Load_Webpage_Click(object sender, EventArgs e) { //if (Cith_Label.Text.Trim() == String.Empty || Title_textBox1.Text.Trim() == String.Empty || Desc_textBox2.Text.Trim() == String.Empty || Name_textBox1.Text.Trim() == String.Empty || Email_textBox2.Text.Trim() == String.Empty || Mobile_textBox1.Text.Trim() == String.Empty) //{ // MessageBox.Show("All fields are required!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); //} //else //{ try { //Declare the Excel Application Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; int rCnt = 0; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(pathinfo, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++) { excelcellpath = (string)(range.Cells[rCnt, 1] as Excel.Range).Value; string url1 = "http://"; string url2 = ".quikr.com/post-classifieds-ads/"; string url = String.Concat(url1 + excelcellpath.ToLower() + url2); geckoWebBrowser1.Navigate(url); while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } HtmlWeb hw = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = hw.Load(url); HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@title='Services'] //div //ul //li[@title='Business Offers'] //a"); string imgSrc = node.Attributes["onclick"].Value; var result = imgSrc.Substring(imgSrc.LastIndexOf('=') + 1); var number = result.Replace(@"'", ""); string uri = String.Concat(url + "?postadcategoryid=" + number); geckoWebBrowser1.Navigate(uri); while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } HtmlWeb hwcity = new HtmlWeb(); HtmlAgilityPack.HtmlDocument city = hwcity.Load(uri); HtmlNode nodecity = city.DocumentNode.SelectSingleNode("//div[@class='formfield'] //div //div[@class='customSingleSelLoc_cont'] //span[1]"); string imgSrccity = nodecity.Attributes["locname"].Value; //string title = Title_textBox1.Text; //string contactname = Name_textBox1.Text; //string emailid = Email_textBox2.Text; //string mobile = Mobile_textBox1.Text; //string textarea = Desc_textBox2.Text; string title = "Non Voice Projects from Direct MNC Signup"; string contactname = "Mohan"; string emailid = "*****@*****.**"; string mobile = "7418832519"; string textarea = "We Provide Genuine Projects which pay high amount and you can get better benefit. We are dealing in Voice, Non Voice, Inbound, Outbound, and Government - Non Government Projects, Online & Offline Processes with Legal Procedure. We also Provide Direct end-client Contact details as an Outsourcing Service Provider company. You have to pay just nominal Security Deposit.Currently we have more than 15 Processes to outsource and Direct MNC sign up. We update our site weekly basis and as per status of process vailability. Interested companies send their company profiles to [email protected] / Skype id: mohanskype43(Mohan)"; geckoWebBrowser1.Document.GetElementById("title").SetAttribute("value", title); geckoWebBrowser1.Document.GetElementById("adlocality").SetAttribute("value", imgSrccity); geckoWebBrowser1.Document.GetElementById("contactName").SetAttribute("value", contactname); geckoWebBrowser1.Document.GetElementById("emailid").SetAttribute("value", emailid); geckoWebBrowser1.Document.GetElementById("mobile").SetAttribute("value", mobile); geckoWebBrowser1.Document.GetElementsByTagName("textarea")[0].InnerHtml = textarea; GeckoInputElement checkbox = new GeckoInputElement(geckoWebBrowser1.Document.GetElementsByName("usrprivacypostad")[0].DomObject); checkbox.Click(); try { while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } GeckoElementCollection newadpost = geckoWebBrowser1.Document.GetElementsByTagName("button"); foreach (GeckoElement currentTag in newadpost) { if (currentTag.GetAttribute("onclick") == "quikrNewPostAd()") { ((GeckoHtmlElement)currentTag).Click(); } } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } } catch (Exception) { while (!geckoWebBrowser1.IsBusy) { Application.DoEvents(); } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } } try { while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } string nowurl = geckoWebBrowser1.Url.ToString(); if (uri == nowurl.ToString()) { GeckoElementCollection photoskip = geckoWebBrowser1.Document.GetElementsByTagName("a"); foreach (GeckoElement phototag in photoskip) { if (phototag.GetAttribute("class") == "submit grey") { ((GeckoHtmlElement)phototag).Click(); } } while (!geckoWebBrowser1.IsBusy) { Application.DoEvents(); } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } string latesturl = geckoWebBrowser1.Url.ToString(); HtmlWeb hwalinkweb = new HtmlWeb(); HtmlAgilityPack.HtmlDocument hwalinkdoc = hwalinkweb.Load(latesturl.ToString()); HtmlNode hwlinknode = hwalinkdoc.DocumentNode.SelectSingleNode("//div[@id='main_textarea'] //div //div //div //div[@id='skip-link'] //a"); string hwllinksource = hwlinknode.Attributes["href"].Value; if (latesturl == geckoWebBrowser1.Url.ToString()) { GeckoElementCollection skippost = geckoWebBrowser1.Document.GetElementsByTagName("a"); foreach (GeckoElement skiptag in skippost) { if (skiptag.GetAttribute("href") == hwllinksource.ToString()) { ((GeckoHtmlElement)skiptag).Click(); } } } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } while (!geckoWebBrowser1.IsBusy) { Application.DoEvents(); } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } } else if (uri != nowurl.ToString()) { while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } string latesturl = geckoWebBrowser1.Url.ToString(); HtmlWeb hwalinkweb = new HtmlWeb(); HtmlAgilityPack.HtmlDocument hwalinkdoc = hwalinkweb.Load(latesturl.ToString()); HtmlNode hwlinknode = hwalinkdoc.DocumentNode.SelectSingleNode("//div[@id='main_textarea'] //div //div //div //div[@id='skip-link'] //a"); string hwllinksource = hwlinknode.Attributes["href"].Value; if (latesturl == geckoWebBrowser1.Url.ToString()) { GeckoElementCollection skippost = geckoWebBrowser1.Document.GetElementsByTagName("a"); foreach (GeckoElement skiptag in skippost) { if (skiptag.GetAttribute("href") == hwllinksource.ToString()) { ((GeckoHtmlElement)skiptag).Click(); } } } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } while (!geckoWebBrowser1.IsBusy) { Application.DoEvents(); } while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } } } catch (Exception) { } geckoWebBrowser1.Navigate("http://www.quikr.com/"); while (geckoWebBrowser1.IsBusy) { Application.DoEvents(); } } } catch (Exception ex) { MessageBox.Show("All Cities Posted Successfully"); } }
private void FillFormField(string id, string value) { if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(value)) { return; } // Only fill out the form field if we have an id if (!string.IsNullOrEmpty(id) || value == ConnectionManager.ParsingConstants.Click) { #region IE if (this.browserType == BrowserType.InternetExplorer) { if (this.internetExplorer.Document == null) { return; } HtmlElement element = this.internetExplorer.Document.GetElementById(id); // The element hasn't been found -> try to find it by name if (element == null) { HtmlElementCollection collection = this.internetExplorer.Document.All; foreach (HtmlElement e in collection) { if (e.Name == id) { element = e; break; } } } if (!string.IsNullOrEmpty(id) && element != null) { if (value != ConnectionManager.ParsingConstants.Click & value != ConnectionManager.ParsingConstants.Redirect && value != ConnectionManager.ParsingConstants.Script) { element.SetAttribute("value", this.ParseValue(value)); } else if (value == ConnectionManager.ParsingConstants.Click) { // Prevent the browser from looping // e.g. a GMail user has entered a wrong pwd // the browser would now loop until the site // (which will never change) chages. if (this.repeatedClickCount >= 1) { return; } this.repeatedClickCount++; element.InvokeMember("click"); } } else if (value == ConnectionManager.ParsingConstants.Click) { HtmlElementCollection collection = this.internetExplorer.Document.All; if (collection == null) { return; } for (int i = 0; i < collection.Count; i++) { element = collection[i]; string type = element.GetAttribute("type"); if (!string.IsNullOrEmpty(type)) { if (element.GetAttribute("type").ToLowerInvariant() == "submit") { // Prevent the browser from looping // e.g. a GMail user has entered a wrong pwd // the browser would now loop until the site // (which will never change) chages. if (this.repeatedClickCount >= 1) { return; } this.repeatedClickCount++; element.InvokeMember("click"); } } } } else if (value == ConnectionManager.ParsingConstants.Redirect & redirected == false) { redirected = true; this.Home = id; this.internetExplorer.Navigate(id); } else if (value == ConnectionManager.ParsingConstants.Script) { string script = id; string functionName = GetScriptFunctionName(ref script); HtmlElement head = internetExplorer.Document.GetElementsByTagName("head")[0]; HtmlElement scriptElement = internetExplorer.Document.CreateElement("script"); scriptElement.SetAttribute("text", script); head.AppendChild(scriptElement); this.internetExplorer.Document.InvokeScript(functionName); } } #endregion #region FF #if GECKO else if (this.browserType == BrowserType.Firefox) { if (this.firefox.Document != null) { GeckoElement element = this.firefox.Document.GetElementById(id); bool useName = false; // The element hasn't been found -> try to find it by name if (element == null) { GeckoElementCollection collection = this.firefox.Document.GetElementsByName(id); if (collection != null && collection.Length >= 1) { element = collection[0]; } useName = true; if (element == null && value != ConnectionManager.ParsingConstants.Redirect && value != ConnectionManager.ParsingConstants.Click && value != ConnectionManager.ParsingConstants.Script) { return; } } if (value != ConnectionManager.ParsingConstants.Click && value != ConnectionManager.ParsingConstants.Redirect && value != ConnectionManager.ParsingConstants.Script) { // The below code doesn't work // element.SetAttribute("value", this.ParseValue(value)); using (AutoJSContext context = new AutoJSContext(firefox.Window.JSContext)) { string result; // by id if (!useName) { context.EvaluateScript(string.Format("document.getElementById('{0}').value = '{1}';", id, this.ParseValue(value)), out result); } // by name else { context.EvaluateScript(string.Format("document.GetElementsByName('{0}')[0].value = '{1}';", id, this.ParseValue(value)), out result); } if (result == null || result.Equals("undefined")) { return; } } } else if (value == ConnectionManager.ParsingConstants.Click) { // Prevent the browser from looping // e.g. a GMail user has entered a wrong pwd // the browser would now loop until the site // (which will never change) chages. if (this.repeatedClickCount >= 1) { return; } this.repeatedClickCount++; if (element == null) { IEnumerable <GeckoHtmlElement> collection = this.firefox.Document.GetElementsByTagName("input"); if (collection == null) { return; } foreach (GeckoHtmlElement el in collection) { string type = el.GetAttribute("type"); if (!string.IsNullOrEmpty(type)) { if (el.GetAttribute("type").ToLowerInvariant() == "submit") { // Prevent the browser from looping // e.g. a GMail user has entered a wrong pwd // the browser would now loop until the site // (which will never change) chages. if (this.repeatedClickCount >= 1) { return; } this.repeatedClickCount++; (el).Click(); } } } } else { ((GeckoInputElement)element).Click(); } } else if (value == ConnectionManager.ParsingConstants.Redirect & redirected == false) { redirected = true; this.Home = id; this.firefox.Navigate(id); } else if (value == ConnectionManager.ParsingConstants.Script) { string script = id; //string functionName = GetScriptFunctionName(ref script); if (prevScript == script) { prevScript = null; return; } if (string.IsNullOrEmpty(prevScript) || prevScript != script) { prevScript = script; } using (AutoJSContext context = new AutoJSContext(firefox.Window.JSContext)) { string result; context.EvaluateScript(script, out result); } } } } #endif #endregion } }
void Browser_DocumentCompleted_Init(object sender, EventArgs e) { GeckoWebBrowser br = sender as GeckoWebBrowser; if (br.Url.ToString() == "about:blank") { return; } GmyDoc = sender as GeckoWebBrowser; if (GmyDoc.Url.ToString().IndexOf("http://webapp.hj8828.com/login.html") >= 0 && isrun == ProcessStatus.初始化) { GeckoElement userName = null; GeckoHtmlElement submit = null; GeckoElementCollection userNames = GmyDoc.Document.GetElementsByTagName("input"); foreach (GeckoHtmlElement item in userNames) { if (item.GetAttribute("value") == "default") { submit = item; } } //myBrowser.Document.GetHtmlElementById("vcodeA").Click(); submit.Click(); isrun = ProcessStatus.结束页面; } if (isrun == ProcessStatus.结束页面) { GeckoHtmlElement namevalue = null; GeckoHtmlElement password = null; GeckoHtmlElement submit = null; GeckoElementCollection userNames = GmyDoc.Document.GetElementsByTagName("input"); GeckoElementCollection userNames1 = GmyDoc.Document.GetElementsByTagName("a"); foreach (GeckoHtmlElement item in userNames) { if (item.GetAttribute("id") == "username") { namevalue = item; } if (item.GetAttribute("id") == "password") { password = item; } } foreach (GeckoHtmlElement item in userNames1) { if (item.GetAttribute("id") == "ensure") { submit = item; } } namevalue.SetAttribute("Value", "w7830"); password.SetAttribute("Value", "123456"); submit.Click(); isrun = ProcessStatus.登录界面; } else if (isrun == ProcessStatus.登录界面) { } }
void wb_Navigating(object sender, GeckoNavigatingEventArgs e) { if (wb.Document != null) { GeckoElementCollection ec = wb.Document.GetElementsByTagName("INPUT"); if (ec != null && ec.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (GeckoElement el in ec) { IEnumerator els = el.Attributes.GetEnumerator(); while (els.MoveNext()) { GeckoAttribute at = (GeckoAttribute)els.Current; sb.Append(at.Name + " " + at.Value + Environment.NewLine); // type password if (at.Name.ToUpper().Equals("TYPE") && at.Value.ToUpper().Equals("PASSWORD")) { posted = true; } } } Logger.__SpecialLogger("Navigate document text: " + sb.ToString()); } } if (loginSuccess) { wb.Stop(); MessageBox.Show("Navigating " + BbQuery.BbLoginString); //wb.Hide(); btnCancel_Click(sender, new EventArgs()); btnCancel.Text = "Logged in"; return; } if (wb.IsBusy) { return; } loginCookie = wb.Document.Cookie; if (loginCookie != null && loginCookie.ToUpper().Contains("SESSION_ID")) { Logger.__SpecialLogger(authUrl + " login cookie at navigating " + wb.Url.AbsoluteUri + " cookie: " + loginCookie); UpdateCookies(loginCookie); object[] args = new object[2]; args[0] = BbQuery.cc; args[1] = dt; bw.RunWorkerAsync(args); while (bw.IsBusy) { Application.DoEvents(); Thread.Sleep(100); } loginSuccess = checkLoginStatus(dt); if (loginSuccess) { wb.Stop(); MessageBox.Show("Navigating " + BbQuery.BbLoginString); // wb.Hide(); btnCancel_Click(sender, new EventArgs()); btnCancel.Text = "Logged in"; } } }