所以我试图使用自动互联网资源管理器从adwords获取一些数据,该脚本运行正常,但过了一段时间它会慢下来爬行。你能看出为什么会发生这种情况或以任何方式规避它的原因吗?
'code to halt internet explorer
Sub WaitForLoad(obj)
Do While ie.Busy: Loop
Do While obj.readyState <> 4: Loop
wscript.sleep(100)
End Sub
'code to save the HTML
Sub SaveHTML(savePath, fileName)
Dim objFileSystem, objOutputFile
Dim strOutputFile
' generate a filename base on the script name
strOutputFile = savePath & fileName & ".html"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile,2, TRUE)
objOutputFile.WriteLine(ie.document.getElementById("btfResults").innerHTML)
objOutputFile.Close
Set objFileSystem = Nothing
End Sub
'create ie object
Set ie = WScript.CreateObject("InternetExplorer.Application")
'set the ie properties
ie.ToolBar = 0
ie.StatusBar = 1
ie.Width = 999
ie.Height = 999
ie.Left = 0
ie.Top = 0
ie.Visible = 1
ie.Navigate "https://adwords.google.co.uk/um/Logout"
WaitForLoad(ie)
dim objFSO,objFile,strContents,objReadFile,WriteStuff
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("logon.log")
Set objReadFile = objFSO.OpenTextFile("logon.log", 1)
strContents = objReadFile.ReadAll
'Wscript.Echo strContents +1
objReadFile.Close
ie.Document.getElementByID("Email").Value = "GMAILADDRESS"
ie.Document.getElementByID("Passwd").Value = "PASSWORD"
'Note: You could just get the form and submit it, but
'you'll miss out on any special JavaScript associated
'with the Submit button.
ie.Document.getElementByID("signIn").Click
WaitForLoad(ie)
ie.Navigate "https://adwords.google.co.uk/o/Targeting/Explorer?"
WaitForLoad(ie)
dim cn, rs,rows
set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
cn.connectionstring = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=test;Uid=root;"
cn.open
WaitForLoad(ie)
ie.Document.getElementsByTagName("input")(3).click
dim j
j=strContents
dim document_start
document_start=ie.Document
Do While true
rs = cn.execute("SELECT * FROM `emails1` WHERE `send`>'"+CStr(j)+"' order by `send` asc limit 0,1")
j=rs(1)
ie.Document.getElementsByTagName("textarea")(0).value=CStr(rs(0))
ie.Document.getElementsByTagName("button")(0).click
WScript.Sleep 4000
dim value,value1,value2,str,str1,i,ssf,ssf1,rep,SECOND,dpth
SECOND=true
dpth=0
Do while (SECOND and dpth<3)
SECOND= false
i=0
'Set WriteStuff = objFSO.OpenTextFile("tst.log", 2, True)
for each value in ie.document.getElementsByTagName("tr")
if (i>14 and i<>17 and i<>18 and i<>19 and i<60 ) then str=str+value.innertext+ "__________________"
i=i+1
next
str = replace(replace(replace(Trim(Replace(Replace(str, vbCrLf, "/"), vbTab, "")),"////// ",""),"/////","////"),"////Keyword///Competition////Global Monthly Searches ////Local Monthly Searches __________________","")
ssf=split(str,"__________________")
for each rep in ssf
if (StrComp(Cstr(rep),"")<>0) then
ssf1=split(rep,"////")
cn.execute("INSERT IGNORE INTO `test`.`emails1` (`word`,`competition`,`GlobalMonthly`,`LocalMonlthly`)VALUES ('"+Cstr(ssf1(0))+"','"+Cstr(ssf1(1))+"','"+Cstr(ssf1(2))+"','"+Cstr(ssf1(3))+"');")
on error resume next
'WriteStuff.WriteLine(Cstr(ssf1(2)) & vbCrLf)
end if
next
for each value in ie.document.all
if (StrComp(Cstr(value.className),"sJQB")=0) then
value.click
dpth=dpth+1
WScript.Sleep 500
SECOND=true
Exit For
end if
next
'WriteStuff.Close
loop
Set WriteStuff = objFSO.OpenTextFile("logon.log", 2, True)
j=j+1
WriteStuff.WriteLine(j)
WriteStuff.Close
ie.document=document_start
loop
ie.quit
我用cmd的wscript运行它。