uibot小作业:检测并输出在科创板审核网站无法搜索到有关公司的证券简称

目录

知识点

1、txt文件读取,分行遍历
2、浏览器调用
3、JS调用:获取对象及其文本
Tips:console测试JS;源代码中不含动态元素;

代码块

function(){
x=document.getElementById("zeroRecordDiv_stock_list")
if (x!=null)
{return x.textContent}
else
{return null}
}
//sRet = File.Read('''C:\Users\huang\Desktop\搜索关键字.txt''',"utf-8")
Dim sRet
Function file_readline(path,sCharset='utf-8')
    Try
        Dim sText= File.Read(path,sCharset)
        dim arrText = Split(sText,"\n")
    Catch err
            TracePrint("错误流程块:" & err["File"] &\
            ",错误信息:" & err["Line"] &\
            ",错误信息:" & err["Message"])
    Else
        Return arrText
        //数组下标从0开始
    End Try
End Function
dim input="C:\\Users\\huang\\Desktop\\搜索关键字.txt"
dim words=file_readline(input)
//Dim nLines  = UBound(words)+1
dim url="http://kcb.sse.com.cn/renewal/index.shtml?"
//dim url0="http://kcb.sse.com.cn/renewal/index.shtml?key=方邦股股份"
dim urls=[]
dim hWeb = WebBrowser.Create("uibotbrowser",url,3000,{"bContinueOnError":false,"iDelayAfter":300,"iDelayBefore":200,"sBrowserPath":"","sStartArgs":""})
For i = 0 To Len(words)-1 step 1
    urls[i]=url&"key="&words[i]
    dim iRet
    iRet= WebBrowser.GoURL(hWeb,urls[i],true,{},30000,{"bContinueOnError":false,"iDelayAfter":300,"iDelayBefore":200})
    sRet = WebBrowser.GetURL(hWeb,{"bContinueOnError":false,"iDelayAfter":300,"iDelayBefore":200})
    dim Ret
    Ret = WebBrowser.RunJS(hWeb,"function(){\nx=document.getElementById(\"zeroRecordDiv_stock_list\")\nif (x!=null)\n{return x.textContent}\nelse\n{return null}\n}",true,{"bContinueOnError":false,"iDelayAfter":300,"iDelayBefore":200})
    If InStr(Ret,"暂无数据",1,false)<>0

        Traceprint(words[i],Ret) 
    else    
        Traceprint(InStr(Ret,"暂无数据",1,false)) 
    End If
Next

上一篇:达人评测 戴尔G3、戴尔G5和G7的区别 哪个好


下一篇:【UiBot实战教程】只要5行代码就能扒小说!?(一)