谁帮我续写完这段程序(很简单的),先送80分,不够再加!我快郁闷死了

qiqilovefeifei 2004-09-21 04:14:18
我在程序中用MSXML2.XMLHTTP组件从网上抓了网页下来,如何在程序中实现将它保存到本地指定路径中?请根据我的程序后接着写一下如何保存到本地指定路径的代码,给出适当的注释,跪着谢你啦!
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
Dim Url,Html
Url="http://www.sohu.com/"
Html = getHTTPPage(Url)
Response.write Html

...全文
177 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovebanyi 2004-09-22
  • 打赏
  • 举报
回复
可能是你的问题吧..我也是生成了.hshh.htm然后
response.redirect("hshh.htm")跳转到这一页.
是不是你的fso有问题.权限之类的什么不够吧
qiqilovefeifei 2004-09-22
  • 打赏
  • 举报
回复
上面的代码是漏掉了一点,但不影响后面我需要的程序, liuxiaoyi666(兔子,用好了GOOGLE才能了解CSDN) 的代码运行通过,但是c盘没有产生1.text文件; lovebanyi(风云天下) 的程序出错,错误是无法找到该网页,请大家再帮忙,我把完整的上部分程序重新贴上去,谢谢大家,请继续关注!!
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'下面试着调用http://www.sohu.com/的html内容
Dim Url,Html
Url="http://www.sohu.com/"
Html = getHTTPPage(Url)
Response.write Html
zhzhuo 2004-09-22
  • 打赏
  • 举报
回复
mark
lovebanyi 2004-09-22
  • 打赏
  • 举报
回复
为什么我的分那么少.
qiqilovefeifei 2004-09-22
  • 打赏
  • 举报
回复
晕死~~~~~~~~~~~~, liuxiaoyi666(兔子,用好了GOOGLE才能了解CSDN) :creattextfile掉了一个字母e,应该是createtextfile,导致我郁闷了两天没找到错在哪儿,终于成功了,我想哭。
顺子 2004-09-22
  • 打赏
  • 举报
回复
這個,不會,
學習~~~~~~~
  • 打赏
  • 举报
回复
上次成功之后,偶的机器的组件服务被我调坏了,现在偶不瞎调了
  • 打赏
  • 举报
回复
不,因为我就不知道我的FSO权限怎么调试
qiqilovefeifei 2004-09-22
  • 打赏
  • 举报
回复
怎么设置这些权限呢??难道你们加上你们写的程序以后测试成功了吗?
  • 打赏
  • 举报
回复
是不是你的fso有问题.权限之类的什么不够
lovebanyi 2004-09-21
  • 打赏
  • 举报
回复


set fso=createobject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile(server.mappath("\hshh.htm"), True)'写到文件hshh.htm中这边可以灵活的进行替换
tf.write(html)
response.redirect("hshh.htm")
  • 打赏
  • 举报
回复
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
end function
Dim Url,Html
Url="http://www.sohu.com/"
Html = getHTTPPage(Url)
Response.write Html
set fso=server.createobject("scripting.filesystemobject")
set obj=fso.creattextfile("c:\1.txt",true,false)
obj.write html
obj.close
lovebanyi 2004-09-21
  • 打赏
  • 举报
回复
好象上面的代码出错了
Drowning 2004-09-21
  • 打赏
  • 举报
回复
Mark

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧