请问怎样用ASP取得网页中的HTML源代码(分不够再加,问题解决,即刻结贴!

yeno 2004-08-04 05:24:33
如题:

比如,我想批量下载某网站的精华贴,存到自己的数据库中,它是以ID号循环显示的(ID:0000001-3000009),现在需要做如下动作:
假设网址:http://www.website.net/web.asp?id=0000001
动作一:自动循环ID号,取得生成HTML页面的代码
http://www.website.net/web.asp?id=0000001
...
...
http://www.website.net/web.asp?id=0000002
http://www.website.net/web.asp?id=3000009
(取得以上页面的代码)
动作二:将所取得的代码存入自己的数据库中

不知我说清楚没有,如果还有疑问请及时给予提醒,鄙人会时刻关注!
谢谢……

...全文
343 25 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
TSD 2004-08-09
  • 打赏
  • 举报
回复
'获取网页HTML内容
Function GetHtmlCode(url)
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
GetHtmlCode=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
End function

'编码转换
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

调用方法:

dim rs,url,gcode,i
url="www.xxx.com/xxx.asp?id="
for i=1 to 3000
gcode=GetHtmlCode(url & i)
-------保存代码开始--------
...
rs("code")=gcode
...
-------保存代码结束--------
next
birdhq 2004-08-09
  • 打赏
  • 举报
回复
强烈关注中,小弟前不久也遇到类似问题~~~
yeno 2004-08-06
  • 打赏
  • 举报
回复
UP
yeno 2004-08-06
  • 打赏
  • 举报
回复
比如说我想下载CSDN上的贴子,应该怎么使贴子自动从第一条循环到第二条,第三条……
就是在客户端实现服务器端的记录连续显示
yeno 2004-08-06
  • 打赏
  • 举报
回复
To aspczlover(执子之手...) , 我是要在人家的服务器端循环显示记录,请问客户机应该如何去控制,光来个
for i=1 to 3000 应该不行吧!
顺子 2004-08-05
  • 打赏
  • 举报
回复
right("000000"&var,n)
yeno 2004-08-05
  • 打赏
  • 举报
回复
我是楼主

非常感谢 aspczlover(执子之手...) 的回复,好像所需要的循环功能还是没有实现
大概程式过程是这样的,先要通过通过验证,然后查看所有贴子,将贴子的代码保存到数据库中。

这中间主要涉及一个循环的问题,也就是我如何让贴子记录从第一条自动循环到最后一条
并在循环过程中将贴子的HTM代码保存到数据库相应的记录中……
lanechng 2004-08-05
  • 打赏
  • 举报
回复
区分大小写??
aspczlover 2004-08-05
  • 打赏
  • 举报
回复
更正一下,服务器端好像区分大小写
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.open "GET", url, False
.Send
GetBody = .ResponseBody '取得数据

'入库
end with
'response.write GetBody
zhuchengyi520 2004-08-05
  • 打赏
  • 举报
回复
这是我一直想做的事,但苦于不知怎么做,最好是有一个例子, 这样更好些
cuixiping 2004-08-05
  • 打赏
  • 举报
回复
赞同楼上。

我觉得也可以用另一种方式,就是先保存为文件,全部下载完后,再从文件存到数据库。
aspczlover 2004-08-05
  • 打赏
  • 举报
回复
<%
for i=1 to 3000

url="http://www.website.net/web.asp?id="&i


Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody '取得数据

'入库


next%>
myxl 2004-08-05
  • 打赏
  • 举报
回复

应该是小于号
<%
maxid=Request("maxid")
id=Request("id")
GetPage("http://****/"&id&".htm")
Conn.Execute("insert....")
if id<maxid then
%>
<script>location.href="本文件.asp?id=<%=id+1%>&maxid=<%=maxid%>";</script>
<%
end if
%>
myxl 2004-08-05
  • 打赏
  • 举报
回复
少打了个最大ID
<%
maxid=Request("maxid")
id=Request("id")
GetPage("http://****/"&id&".htm")
Conn.Execute("insert....")
if id>maxid then
%>
<script>location.href="本文件.asp?id=<%=id+1%>&maxid=<%=maxid%>";</script>
<%
end if
%>
myxl 2004-08-05
  • 打赏
  • 举报
回复
<%
maxid=Request("maxid")
id=Request("id")
GetPage("http://****/"&id&".htm")
Conn.Execute("insert....")
if id>maxid then
%>
<script>location.href="本文件.asp?id=<%=id+1%>";</script>
<%
end if
%>
BillSmiph 2004-08-05
  • 打赏
  • 举报
回复
mark
yeno 2004-08-05
  • 打赏
  • 举报
回复
怎样使数据循环和怎样将获得的数据按照贴子存入到数据库中呢?

假如:有3000篇贴子,在我的数据库中同时也添加3000条记录,保存着这三千篇贴子的HTML代码
aspczlover 2004-08-05
  • 打赏
  • 举报
回复
<%
for i=1 to 3000
...
next%>
这样不能实现吗,呵呵我想一次入库不容易,
机器承受不了吧可能
分几次导入比较好
rijcm 2004-08-04
  • 打赏
  • 举报
回复
关注!
aspczlover 2004-08-04
  • 打赏
  • 举报
回复
<body>
xmlhttp
<div id="demo"> <div style="width: 677; height: 70">
<input type="button" value="按钮" name="B3">


<script language=vbscript>

sub b3_onclick


Dim objXMLHTTP, xml
Set xml = CreateObject("Microsoft.XMLHTTP")

xml.Open "GET", "http://www.eyou.com", False
xml.Send
demo.innertext= bytes2BSTR(xml.responsebody)
Set xml = Nothing
end sub

Function bytes2BSTR(vIn)
dim strReturn
dim i1,ThisCharCode,NextCharCode
strReturn = ""
For i1 = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i1,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i1+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i1 = i1 + 1
End If
Next
bytes2BSTR = strReturn
End Function

</script>


</body>
加载更多回复(5)

28,408

社区成员

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

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