【问题标题】:Get web page text in msgbox在 msgbox 中获取网页文本
【发布时间】:2016-11-20 04:53:07
【问题描述】:

我试图在我的代码发送后显示一个 msgbox。 我想显示内部文本。

到现在为止

 ie = CreateObject("InternetExplorer.Application")
 ie.Navigate("http://www.webpage.com.au/")
 ie.Visible = True
 mesg = TextBox1.Text.ToString()
 pw = "....." ie.Document.All("password").Value = pw
 ie.Document.All("idpagers").Value = Id
 ie.Document.All("message").Value = mesg
 ie.Document.All("Send").Click()
 pID = ie.Document.All().ToString

 MessageBox.Show(pID)

但这显示了system.object.blah.blah

【问题讨论】:

  • Vb 脚本对不起,我添加了错误的标签
  • 问题是使用ToString(),它只是给你一个字符串表示你调用它的对象,因此System.Object等。使用InnerHTML()innerText()而不是返回HTML表示DOM 元素或只是文本表示。
  • @Lankymart 您能否举个例子作为答案,如果正确,我可以标记为已回答
  • 这里已经有两个答案,使用InnerText()InnerHTML() 的详细信息,我只是指出ToString() 没有给你你所期望的。

标签: internet-explorer vbscript com messagebox


【解决方案1】:

试试这个代码:

Const TriStateTrue = -1 ' Pour la prise en charge de l'Unicode
URL = InputBox("Entrez l'URL pour y extraire son Code Source HTML "&vbcr&vbcr&_
"Exemple ""http://www.google.fr""","Extraction du Code Source © Hackoo © 2013","http://www.google.fr")
If URL = "" Then WScript.Quit
Titre = "Extraction du Code Source de " & URL
Set ie = CreateObject("InternetExplorer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
ie.Navigate(URL)
ie.Visible=false
DO WHILE ie.busy
LOOP
DataHTML = ie.document.documentElement.innerHTML
strFileHTML = "CodeSourceHTML.txt"
Set objHTMLFile = objFSO.OpenTextFile(strFileHTML, 2, True, TriStateTrue)
objHTMLFile.WriteLine(Titre&vbcrLF&String(120,"*"))
objHTMLFile.WriteLine(DataHTML)
objHTMLFile.Close
ie.Quit
Set ie=Nothing
wscript.echo DataHTML
 Ouvrir(strFileHTML)
wscript.Quit

Function Ouvrir(File)
    Set ws=CreateObject("wscript.shell")
    ws.run "Notepad.exe "& File,1,False
end Function

【讨论】:

    【解决方案2】:
    Do 
        wscript.sleep 50            
    Loop Until ie.document.readystate = "complete"
    

    把它放在导航之后。您必须等待页面加载。

    这会将 html 文本分配给页面,然后提取纯文本。

    Set ie = CreateObject("InternetExplorer.Application") 
    ie.Visible = 0
    ie.Silent = 1 
    ie.Navigate2 "file://" & FilterPath & "Filter.html"
    Do 
        wscript.sleep 50            
    
    Loop Until ie.document.readystate = "complete"
    ie.document.body.innerhtml = Inp.readall
    Outp.write ie.document.body.innertext
    

    【讨论】:

    • 我把这个类似的东西放在我的真实中,但结果相同
    猜你喜欢
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2019-04-30
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多