導航:首頁 > 編程大全 > webbrowser密碼框

webbrowser密碼框

發布時間:2024-05-05 05:26:47

Ⅰ 怎麼在VBA中輸入密碼

可以通過WebBrowser控制項的使用實現該功能
以下實例打開網路,在輸入框輸入「aaa」
Public Sub useie()
'引用Microsoft Internet Controls
Dim IE
On Error Resume Next
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True

IE.Navigate URL:="https://www..com/"
timeie = DateAdd("s", 20, Now()) '等待20s
Do While IE.Busy And Not IE.ReadyState = READYSTATE_COMPLETE
DoEvents
If timeie < Now() Then
MsgBox 「無法連接重新執行」
IE.Quit
Exit Sub
End If
Loop

IE.Document.getElementById("kw").Value = "aaa"
Set IE = Nothing
Set ID = Nothing
End Sub

WebBrowser控制項的使用
0、常用方法
Navigate(string urlString):瀏覽urlString表示的網址
Navigate(System.Uri url):瀏覽url表示的網址
Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders): 瀏覽urlString表示的網址,並發送postData中的消息
//(通常我們登錄一個網站的時候就會把用戶名和密碼作為postData發送出去)
GoBack():後退
GoForward():前進
Refresh():刷新
Stop():停止
GoHome():瀏覽主頁
WebBrowser控制項的常用屬性:
Document:獲取當前正在瀏覽的文檔
DocumentTitle:獲取當前正在瀏覽的網頁標題
StatusText:獲取當前狀態欄的文本
Url:獲取當前正在瀏覽的網址的Uri
ReadyState:獲取瀏覽的狀態
WebBrowser控制項的常用事件:
DocumentTitleChanged,
CanGoBackChanged,
CanGoForwardChanged,
DocumentTitleChanged,
ProgressChanged,
ProgressChanged

1、獲取非input控制項的值:
webBrowser1.Document.All["控制項ID"].InnerText;
或webBrowser1.Document.GetElementById("控制項ID").InnerText;
或webBrowser1.Document.GetElementById("控制項ID").GetAttribute("value");

2、獲取input控制項的值:
webBrowser1.Document.All["控制項ID"].GetAttribute("value");;
或webBrowser1.Document.GetElementById("控制項ID").GetAttribute("value");

3、給輸入框賦值:
//輸入框
user.InnerText = "myname";
password.InnerText = "123456";
webBrowser1.Document.GetElementById("password").SetAttribute("value", "Welcome123");

4、下拉、復選、多選:

//下拉框:
secret.SetAttribute("value", "question1");
//復選框
rememberme.SetAttribute("Checked", "True");
//多選框
cookietime.SetAttribute("checked", "checked");

5、根據已知有ID的元素操作沒有ID的元素:
HtmlElement btnDelete = webBrowser1.Document.GetElementById(passengerId).Parent.Parent.Parent.Parent.FirstChild.FirstChild.Children[1].FirstChild.FirstChild;

根據Parent,FirstChild,Children[1]數組,多少層級的元素都能找到。

6、獲取Div或其他元素的樣式:
webBrowser1.Document.GetElementById("addDiv").Style;

7、直接執行頁面中的腳本函數,帶動態參數或不帶參數都行:
Object[] objArray = new Object[1];
objArray[0] = (Object)this.labFlightNumber.Text;
webBrowser1.Document.InvokeScript("ticketbook", objArray);
webBrowser1.Document.InvokeScript("return false");

8、自動點擊、自動提交:
HtmlElement btnAdd = doc.GetElementById("addDiv").FirstChild;
btnAdd.InvokeMember("Click");

9、自動賦值,然後點擊提交按鈕的時候如果出現腳本錯誤或一直載入的問題,一般都是點擊事件執行過快,這時需要藉助Timer控制項延遲執行提交按鈕事件:

this.timer1.Enabled = true;
this.timer1.Interval = 1000 * 2;
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
ClickBtn.InvokeMember("Click");//執行按扭操作
}

10、屏蔽腳本錯誤:
將WebBrowser控制項ScriptErrorsSuppressed設置為True即可

11、自動點擊彈出提示框:

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
//自動點擊彈出確認或彈出提示
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); //彈出確認
vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");//彈出提示
}

WebBrowser頁面載入完畢之後,在頁面中進行一些自動化操作的時候彈出框的自動點擊(屏蔽)

private void webBrowser1_DocumentCompleted(object sender, e)
{
//自動點擊彈出確認或彈出提示
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); //彈出確認
vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");//彈出提示
//下面是你的執行操作代碼
}

12、獲取網頁中的Iframe,並設置Iframe的src
HtmlDocument docFrame = webBrowser1.Document.Window.Frames["mainFrame"].Document;

HtmlDocument docFrame = webBrowser1.Document.All.Frames["mainFrame"].Document;
docFrame.All["mainFrame"].SetAttribute("src", "http://www..com/");

13、網頁中存在Iframe的時候webBrowser1.Url和webBrowser1_DocumentCompleted中的e.Url不一樣,前者是主框架的Url,後者是當前活動框口的Url。

14、讓控制項聚焦
this.webBrowser1.Select();
this.webBrowser1.Focus();
doc.All["TPL_password_1"].Focus();

15、打開本地網頁文件
webBrowser1.Navigate(Application.StartupPath + @"\Test.html");

16、獲取元素、表單

//根據Name獲取元素
public HtmlElement GetElement_Name(WebBrowser wb,string Name)
{
HtmlElement e = wb.Document.All[Name];
return e;
}

//根據Id獲取元素
public HtmlElement GetElement_Id(WebBrowser wb, string id)
{
HtmlElement e = wb.Document.GetElementById(id);
return e;
}

//根據Index獲取元素
public HtmlElement GetElement_Index(WebBrowser wb,int index)
{
HtmlElement e = wb.Document.All[index];
return e;
}

//獲取form表單名name,返回表單
public HtmlElement GetElement_Form(WebBrowser wb,string form_name)
{
HtmlElement e = wb.Document.Forms[form_name];
return e;
}

//設置元素value屬性的值
public void Write_value(HtmlElement e,string value)
{
e.SetAttribute("value", value);
}

//執行元素的方法,如:click,submit(需Form表單名)等
public void Btn_click(HtmlElement e,string s)
{

e.InvokeMember(s);
}

Ⅱ 怎麼設置webbrowser設置代理用戶名和密碼

var credentialStringValue = "user:pass";
var credentialByteArray = ASCIIEncoding.ASCII.GetBytes(credentialStringValue);
var credentialBase64String = Convert.ToBase64String(credentialByteArray);

Object nullObject = 0;
Object nullObjectString = "";
Object authObject = string.Format("Proxy-Authorization: Basic {0}{1}", credentialBase64String, Environment.NewLine);

browser.Navigate(args.Url, ref nullObject, ref nullObject, ref nullObjectString, ref authObject);

Ⅲ C# 使用webBrowser控制項獲取網頁中的賬號密碼登錄網頁元素並自動填寫模擬自動登錄

QQ音樂登錄的方式好像是API的方式,給你兩個方案

1、API方式:然後輸入對應的參數,你就可以登錄成功,這時你就可以做自己的想做的事了

2、模擬點擊(selenium)方式:即使利用seleium模擬滑鼠點擊網頁,實現登錄,這個方式屬於笨拙的方式

注意:有時候可能出現需要輸入驗證碼,這時你就需要識別驗證碼,給你推薦 tesseract-ocr 這個插件,源碼地址tesseract-orc 不明白的留言吧

Ⅳ c#添加webBrowser控制項,如何實現自動填寫打開的網頁中的登錄帳號,密碼,並且自動登陸

cookie
打開網頁時進行cookie認證(可考慮對cookie與IP的認證)
在Page_load裡面進行cookie認證,認證通過直接跳轉到登錄後頁面(為啥自動登錄還要填登錄賬號和密碼呢...)

閱讀全文

與webbrowser密碼框相關的資料

熱點內容
d4252用什麼軟體編程 瀏覽:35
大學生如何參與大數據 瀏覽:779
autocad3維教程 瀏覽:2
港澳台版本有什麼區別 瀏覽:263
java四個月能學到什麼 瀏覽:46
開發板和linux文件 瀏覽:202
appstore外國帳號怎麼看預約游戲 瀏覽:137
有什麼免費加速網站的cdn 瀏覽:781
哪個文件存在最安全 瀏覽:199
淘寶導航欄分割線代碼 瀏覽:271
win10開不了機按f8沒用 瀏覽:12
河南營銷網站推廣多少錢 瀏覽:135
華為暢享6手機文件管理 瀏覽:939
linux驅動環境 瀏覽:893
ae用什麼打開文件 瀏覽:877
湖南嶽陽大數據中心 瀏覽:710
DSP大數據公司 瀏覽:510
win10檢測不到u盤啟動 瀏覽:941
電腦文件怎麼重命名文件 瀏覽:507
哪個協議用來傳輸文件協議 瀏覽:61

友情鏈接