大家好!本人不懂vba,对代码也不是太熟悉。我这有几个代码希望大家帮忙把难点句子注释一下,另外代码里有整个的语句还希望帮忙说明一下这整个语句表示的是什么内容。谢谢了!代码如下:
代码一:
Sub test()
With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "http://www.sephora.cn/html/imagesNew/btn_goGrey.gif”
DoEvents
While.busy
DoEvents
Wend
With .Document
.GetElementById("username").Value = "hyangyang0613"
.GetElementById("password").Value = "hyy379509"
.GetElementById("loginsubmit").Click
End With
End With
End Sub
代码二:
Dim strSch As String
Dim ImgButton, schText
strSch = ThisWorkbook.Sheets("sheet1").Cells(1, 1)
For Each schText In WebBrowser1.Document.All
If LCase(schText.tagname) = "input" Then
If LCase(schText.Type) = "text" Then
If schText.Name = "searchText" Then
schText.Value = strSch 'text
End If
End If
End If
Next
'form1.searchText
For Each ImgButton In WebBrowser1.Document.All
If LCase(ImgButton.tagname) = "input" Then
If LCase(ImgButton.Type) = "image" Then
'If ImgButton.src = " http://www.xxxxxxxx" Then
ImgButton.Click '点击
'End If
End If
End If
Next
代码三:
Dim shResult
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("G:\sh.txt", True)
For Each shResult In WebBrowser1.Document.getElementsByTagName("table") '
a.WriteLine (shResult.InnerText)
a.Close
Next
整个的语句:比如说在代码二里从第一个if到第一个end if结束这是一个语句集,那说明这个语句表示的是什么?
我这么说希望大家能看明白。呵呵!!又要麻烦各位了。我也可以学习学习。呵呵!!循环语句也帮忙说明一下吧。
代码一:
Sub test()
With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "http://www.sephora.cn/html/imagesNew/btn_goGrey.gif”
DoEvents
While.busy
DoEvents
Wend
With .Document
.GetElementById("username").Value = "hyangyang0613"
.GetElementById("password").Value = "hyy379509"
.GetElementById("loginsubmit").Click
End With
End With
End Sub
代码二:
Dim strSch As String
Dim ImgButton, schText
strSch = ThisWorkbook.Sheets("sheet1").Cells(1, 1)
For Each schText In WebBrowser1.Document.All
If LCase(schText.tagname) = "input" Then
If LCase(schText.Type) = "text" Then
If schText.Name = "searchText" Then
schText.Value = strSch 'text
End If
End If
End If
Next
'form1.searchText
For Each ImgButton In WebBrowser1.Document.All
If LCase(ImgButton.tagname) = "input" Then
If LCase(ImgButton.Type) = "image" Then
'If ImgButton.src = " http://www.xxxxxxxx" Then
ImgButton.Click '点击
'End If
End If
End If
Next
代码三:
Dim shResult
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("G:\sh.txt", True)
For Each shResult In WebBrowser1.Document.getElementsByTagName("table") '
a.WriteLine (shResult.InnerText)
a.Close
Next
整个的语句:比如说在代码二里从第一个if到第一个end if结束这是一个语句集,那说明这个语句表示的是什么?
我这么说希望大家能看明白。呵呵!!又要麻烦各位了。我也可以学习学习。呵呵!!循环语句也帮忙说明一下吧。
1、模拟页面登录。
2、自动填写搜索内容,自动点击图片。
3、获取table内容写入到文件中,不包含HTML格式代码。
.Visible = True
.navigate "http://www.sephora.cn/html/imagesNew/btn_goGrey.gif”
DoEvents
While.busy
DoEvents
Wend
With .Document
.GetElementById("username").Value = "hyangyang0613"
.GetElementById("password").Value = "hyy379509"
.GetElementById("loginsubmit").Click
End With
End With这段代码是输入用户名: hyangyang0613, 输入口令:hyy379509, 然后登录。 If LCase(schText.tagname) = "input" Then
If LCase(schText.Type) = "text" Then
If schText.Name = "searchText" Then
schText.Value = strSch 'text
End If
End If
End If这段代码是在网页中找到用于填写搜索内容的文本框,然后将第一个单元格的内容填入搜索框
搜索框类型:INPUT 名称:searchText,
内容:strSch = ThisWorkbook.Sheets("sheet1").Cells(1, 1),schText.Value = strSchIf LCase(ImgButton.tagname) = "input" Then
If LCase(ImgButton.Type) = "image" Then
'If ImgButton.src = " http://www.xxxxxxxx" Then
ImgButton.Click '点击
'End If
End If
End If同二,查找并点击搜索图片。搜索图片:INPUT 类型:Image ,
图片的链接:http://www.xxxxxxxx, 点击动作:ImgButton.Click For Each shResult In WebBrowser1.Document.getElementsByTagName("table") '
a.WriteLine (shResult.InnerText)
a.Close查找网页内所有表格的内容并写入G:\sh.txt
代码中的循环语句:
因为每个网页WebBrowser1.Document.All中都有许许多多的元素,例如body,table,tr,td,input,line等等,你没办法直接定位到其中的某个上,所以只能根据 Name 和 Type 来定位,这样才能找到你需要的元素。明白了吗。你可以调试代码是用单步执行方式,来看看WebBrowser1.Document.All中的对象,网页越大,对象越多,看看就知道了。
DoEvents
Wend
作用:等待网页加载完毕
If LCase(schText.tagname) = "input" Then
If LCase(schText.Type) = "text" Then
If schText.Name = "searchText" Then
schText.Value = strSch 'text
End If
End If
End If
可以写成:
If LCase(schText.tagname) = "input" And LCase(schText.Type) = "text" And schText.Name = "searchText" Then schText.Value = strSch
If LCase(ImgButton.tagname) = "input" Then
If LCase(ImgButton.Type) = "image" Then
'If ImgButton.src = " http://www.xxxxxxxx" Then
ImgButton.Click '点击
'End If
End If
End If
可以写成:
If LCase(ImgButton.tagname) = "input" And LCase(ImgButton.Type) = "image" Then ImgButton.Click
Next
应改为
Next
a.Close