“预期声明”在VB脚本中
我是 vbscript 新手。我收到错误
预计在 get_html 处声明
我的代码的底部。我实际上试图为变量 get_html
声明一个值(即一个 url)。我该如何解决这个问题?
Module Module1
Sub Main()
End Sub
Sub get_html(ByVal up_http, ByVal down_http)
Dim xmlhttp : xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
xmlhttp.open("get", up_http, False)
xmlhttp.send()
Dim fso : fso = CreateObject("scripting.filesystemobject")
Dim newfile : newfile = fso.createtextfile(down_http, True)
newfile.write(xmlhttp.responseText)
newfile.close()
newfile = Nothing
xmlhttp = Nothing
End Sub
get_html _"http://www.somwwebsite.com", _"c:\downloads\website.html"
End Module
I'm new to vbscript. I get the error
Declaration expected at get_html
At the bottom part of my code. I am actually trying to declare a value (which is a url) for the variable get_html
. How can I resolve this?
Module Module1
Sub Main()
End Sub
Sub get_html(ByVal up_http, ByVal down_http)
Dim xmlhttp : xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
xmlhttp.open("get", up_http, False)
xmlhttp.send()
Dim fso : fso = CreateObject("scripting.filesystemobject")
Dim newfile : newfile = fso.createtextfile(down_http, True)
newfile.write(xmlhttp.responseText)
newfile.close()
newfile = Nothing
xmlhttp = Nothing
End Sub
get_html _"http://www.somwwebsite.com", _"c:\downloads\website.html"
End Module
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能希望将对
get_html
的调用移至Main
子例程 (Sub Main()
) 内进行调用。例如:据我所知,您不能直接从模块内进行函数调用。
You probably want to move your call to
get_html
to be a call from within yourMain
subroutine (Sub Main()
). For example:AFAIK, you can't make function calls from directly within a module.
存在一些语法错误。
下划线
)xmlhttp.open
是sub,不返回任何内容)。调用子例程有两种主要选择。sub_proc param1, param2
或Call sub_proc(param1, param2)
=
”对于对象来说是不够的。你应该使用设置声明。它将对象引用分配给
变量。
响应可能会以 utf-8 编码形式返回。但 FSO 与 utf-8 并不一致。另一种选择是将响应写入 unicode(将
True
作为第三个参数传递给 创建文本文件)但输出大小将大于应有的大小。因此我更愿意使用 < strong>Stream 对象。
我修改了你的代码。请考虑。
There are some syntax mistakes.
underscore
on page)xmlhttp.open
is a sub, does not return anything). You have two main alternatives to calling a sub routine.sub_proc param1, param2
orCall sub_proc(param1, param2)
=
' is not enough for the objects. You shoulduse Set statement. It assigns object references to the
variables.
The response may be return as utf-8 encoded. But however FSO is not at peace with utf-8. Another option is to write the response as unicode (passing
True
as third parameter to CreateTextFile)but the output size will be larger than it should be. Therefore I would prefer to use Stream object.
I've revised your code. Please consider.