十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
我将你的上面的html代码复制到一个test.html文件中
创新互联网络公司拥有十多年的成都网站开发建设经验,上千客户的共同信赖。提供成都网站建设、成都做网站、网站开发、网站定制、买友情链接、建网站、网站搭建、响应式网站、网页设计师打造企业风格,提供周到的售前咨询和贴心的售后服务
html
head
titleTest Page/title
/head
body
input name="txtCSRQ" class="textbox" id="txtCSRQ" type="text" readonly="readonly" value="1993-05-10"/
/body
/html
然后在vb.net的webbrowser中加载这个test.html,加载完毕后点击一个按钮获取input的value值,实现代码如下:
' 此方法为Form1的加载事件
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 加载本地文档test.html
WebBrowser1.Url = New Uri(String.Format("{0}/test.html", Application.StartupPath))
' 文档没有加载完毕之前将按钮禁用
Button1.Enabled = False
End Sub
' 此方法为Button1的Click事件
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim doc As HtmlDocument = WebBrowser1.Document
' 查找ID为txtCSRQ的元素
Dim element As HtmlElement = doc.GetElementById("txtCSRQ")
' 如果找到了改元素
If element IsNot Nothing Then
' 显示该元素的值
MessageBox.Show(element.GetAttribute("value"))
End If
End Sub
' 此方法为WebBrowser的DocomentCompleted事件
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
' 文档test.html加载完毕后,使按钮可用
Button1.Enabled = True
End Sub
Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String
'启动一次具体的数据采集工作,返回采集到的HTML内容:要求必须输入带://的全地址数据
On Error Resume Next
Dim Str_WebContent As String = "请输入查找网站地址."
Dim wb As WebClient = New WebClient() '//创建一个WebClient实例
If mWebsiteUrl.IndexOf("://") 0 Then
'//获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。(可有可无)
wb.Credentials = CredentialCache.DefaultCredentials
'//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)
'//转换字符
If mWebsiteType Then
Str_WebContent = Encoding.Default.GetString(pagedata)
Else
Str_WebContent = Encoding.UTF8.GetString(pagedata)
End If
End If
Return Str_WebContent '提取出来新闻内容,删除Body前后的多余内容,同时补充上该 Body标记,形成完整的内容 Str_WebContent '
End Function
For Each h_e As HtmlElement In WebBrowser1.Document.GetElementsByTagName("Value")
h_e.OuterText = "修改后的值"
Next
是执行button的click事件吗?不过要知道button的id才可以。
webbrowser1.Document.GetElementById(button的id).InvokeMember("click");
这个问题有点意思,但题主表意不明,确切的说应该分Web端和客户端两种情况。
想来问到这个问题的不应该是开发Web端的,说说客户端的吧:
1、HttpWebRequest.CookieContainer
Cookies通过HttpResponse传给客户端,通过HttpRequest传回服务端,因此你可以
设置Response.Cookies集合的值修改Cookie
1
Response.Cookies("MyCookie")("Data") = myCookie
通过读取Request.Cookies集合的值得到Cookies的值
1
myCookie =Request.Cookies("MyCookie")("Data") ""
2、本人自编的一个函数,放到一个模块里直接调用即可:
Dim myCookie As String
Public Function LoginAnGetCookie(ByRef sUser As String, ByRef sPass As String) As String()
On Error Resume Next
REM 登录网站并获得cookie
Dim url As String = "网站地址"
Dim postData As String = "sUser=" sUser "sPass=" sPass '假设传值的是这样的,实际中可用Fiddler抓取。
Dim wc As System.Net.WebClient = New System.Net.WebClient
Rem wc.Headers.Add("Cookie", myCookie) '可讲第一次获得的Cookie赋值给myCookie,然后在此处传值给网站即可
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
wc.Headers.Add("UserAgent", "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10)")
Dim sHtml As String = wc.UploadString(url, "POST", postData)
Dim arrAllKeys() As String = wc.ResponseHeaders.AllKeys
Dim sCookies As String = "Set-Cookie"
For i As Integer = 0 To arrAllKeys.Length - 1
If arrAllKeys(i).Equals("Set-Cookie") Then sCookies = wc.ResponseHeaders.Get(i)
Next i
Return New String() {sHtml, sCookies} '返回二维数组,其中LoginAnGetCookie(0)是网页源代码,LoginAnGetCookie(1)是登录后的Cookie
End Function