Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As LongPrivate Sub Form_Load() Dim fs, f '将网页下载并保存到本地文件temp.txt中 If Not URLDownloadToFile(0, "http://www.cngoos.cn/alexapp.asp", "temp.txt", 0, 0) Then '读取文件到TEXT1中 Set fs = CreateObject("scripting.filesystemobject") Set f = fs.opentextfile("temp.txt", 1) Text1.Text = f.readall f.Close Set fs = Nothing '删除文件 Kill "temp.txt" End If End Sub
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As LongPrivate Sub Form_Load() Dim fs, f If Not URLDownloadToFile(0, "http://www.cngoos.cn/alexapp.asp", "temp.txt", 0, 0) Then Set fs = CreateObject("scripting.filesystemobject") Set f = fs.opentextfile("temp.txt", 1) Text1.Text = Replace(f.readall, vbCrLf, "") f.Close Set fs = Nothing Kill "temp.txt" End If End Sub
你的第一行也有问题,显示到Text1中,这个应该是前台的
东西吧,直接给对象付值不就可以了:
<intut Name='Text1' Valur='<%=Server.HTMLEncode(YourText)%>'>
你是想读取前台HTML文件的第一行还是后台脚本的第一行?
前台的可以用Script的Document对象
后台可以用FSO或自己开发组件。
要不用XMLHTTP来要数据处理也可以。看你爱怎么做了。
s=inet1.openurl("www.cngoos.cn/alexapp.asp")
'取第一行
s = Left(s, InStr(1, s, vbcrlf))
'用inet控件取得网页内容
s=inet1.openurl("www.cngoos.cn/alexapp.asp")
'取第一行
s = Left(s, InStr(1, s, vbcrlf))
用了, 没任何效果啊!!
....第一行这个概念太模糊了<body>中的第一行??碰上了html标记你又怎么处理??
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.applevb.com"
End Sub
然后用以下代码来获取
WebBrowser1..Document.body.innertext
楼上的都说得很清楚了,总结一下就是:第一步,取网页内容(用inet或webbrowser)存入字符串,第二步,根据要求处理字符串。
可以 存了之后没任何效果啊
Dim fs, f
'将网页下载并保存到本地文件temp.txt中
If Not URLDownloadToFile(0, "http://www.cngoos.cn/alexapp.asp", "temp.txt", 0, 0) Then
'读取文件到TEXT1中
Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.opentextfile("temp.txt", 1)
Text1.Text = f.readall
f.Close
Set fs = Nothing
'删除文件
Kill "temp.txt"
End If
End Sub
Dim fs, f
If Not URLDownloadToFile(0, "http://www.cngoos.cn/alexapp.asp", "temp.txt", 0, 0) Then
Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.opentextfile("temp.txt", 1)
Text1.Text = Replace(f.readall, vbCrLf, "")
f.Close
Set fs = Nothing
Kill "temp.txt"
End If
End Sub