当前位置:编程学习 > VB >>

vb操作网站内容

我想用VB对网站进行操作,网站是显示在WEB控件里的了。
按钮代码:
<input name="0acb31fd" id="0acb31fd" type="button" value="确认投注" onclick="return isdo('-218','-140')" />  <strong>标准模式:</strong><a href="javascript:FirstModes(1)" class='a1'>全包</a><a href="javascript:FirstModes(2)" class='a1'>单</a><a href="javascript:FirstModes(3)" class='a1'>双</a><a href="javascript:FirstModes(4)" class='a1'>大</a><a href="javascript:FirstModes(5)" class='a1'>小</a><a href="javascript:FirstModes(6)" class='a1'>中</a><a href="javascript:FirstModes(7)" class='a1'>边</a></td></tr>

我就是想用VB对那个确认投注进行操作,点了确认投注后还会有个提示框,代码如下:

<tr>
<td width="19%" rowspan="2" align="right"> </td>
<td width="81%" height="25" align="left">       <span class="STYLE1">确认你投注?将扣除你<font color=red><span id="postgoldeggs">0</span></font>个金蛋!</span></td>
</tr>
<tr>
<td height="25" align="left">  <input type="checkbox" name="isdb" id="isdb" value="1" onclick="return ischecked()" />
<span class="STYLE1">按当前投注模式与比例进行自动投注</span></td>
</tr>
<tr>
<td> </td>
<td height="30"align="left" valign="bottom">  
<input type="button" id="button2" name="button1" value=" 确 定 " onclick="return datapost()"> 
<input type="button" id="button3" name="button2" value=" 取 消 " onclick="return rm();" >
</td>
</tr>
</table>


然后就是点这个确认,就可以了。


还有就是通过VB来对网站的文本框进行操作。文本框代码:
<input id="SMONEYSUM2" class="input1" name="SMONEYSUM2" readonly="readonly" type="text"
value="0" />  

我就是想填写数字进去。要怎么做?用VB怎么做?

还有对选项框进行操作,选项框代码:
<td align="center" bgcolor="#f4f4f4">
<input name="CI" onclick="chkCI(1);" type="checkbox" value="1" /></td>
用VB怎么对这些进行操作??
谢谢。
答案:下面我完成第一个点击“确认投注”的操作:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.length - 1 '检测所有标签
If UCase(vDoc.All(i).tagName) = "input" Then '找到input标签
Set vTag = vDoc.All(i)
If vTag.Type = "button" And vTag.Value = "确认投注" Then '找到确定按钮。
vTag.Select '按钮获得焦点,可以省略
vTag.Click '点击提交了,一切都OK了
End If
End If
Next i
End Sub

DocumentComplete事件是指web控件载入完成所触发的标志。而其下面的代码就很好解释了,首先是根据标签,type,value获得指定控件的焦点,再发送点击指令。

下面的确定也是一样的方法。其次,文本框的操作方法也是类似的,在此我不一一列举。如果你感到困扰的话,可以加我QQ 138001655,我会亲自教你的。不过我很需要你的分数!谢谢成全。

数据库结构:
--------------------------------------
test.mdb [放在BIN目录下]
表 test(id 自动编号, img OLE)
----------------------------------------------

代码:
----------------------------------------------------
使用 一个 openfiledialog ,两个 picturebox

----------------------------------------------------------------------
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form

Dim cnn As Data.OleDb.OleDbConnection

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Dispose(True)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub

Private Sub DBInit()
Try
cnn = New Data.OleDb.OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Application.StartupPath & "\test.mdb")
cnn.Open()
Catch exp As OleDb.OleDbException
MsgBox(exp.Message)
End
End Try
End Sub

Private Sub DBRelease()
cnn.Close()
cnn = Nothing
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If PictureBox1.Image Is Nothing Then
MsgBox("请先选择图片", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim fs As FileStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim bt(fs.Length) As Byte
fs.Read(bt, 0, fs.Length)
fs.Close()
fs = Nothing
Dim oleCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
DBInit()
oleCmd.Connection = cnn
oleCmd.CommandType = CommandType.Text
oleCmd.CommandText = "INSERT INTO test (img) VALUES (@img)"
oleCmd.Parameters.Add("@img", OleDb.OleDbType.Binary).Value = bt
oleCmd.ExecuteNonQuery()
oleCmd = Nothing
DBRelease()
MsgBox("图片插入成功")
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim oleCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT img FROM test WHERE id=1")
oleCmd.CommandType = CommandType.Text
DBInit()
oleCmd.Connection = cnn
Dim dr As OleDb.OleDbDataReader = oleCmd.ExecuteReader(CommandBehavior.SingleRow)

上一个:VB二进制打开JPG文件
下一个:怎么能在短时间内学会VB

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,