请教高手:如何用vb实现,把指定网页保存为txt文本的功能
求源码。至少能实现相当于“用ie打开指定网址,然后另存为某某.txt”的功能。
谢谢。 VB Internet Explorer 源代码 --------------------编程问答-------------------- liburl ? --------------------编程问答-------------------- 仅供参考
Private Function StrFormat(s As String) As String--------------------编程问答--------------------
On Error Resume Next
Dim Buf As String
Dim StrTemp As String
Dim c As String
Dim i As Long
Dim j As Long
Dim k As Long
Dim L As Long
Buf = s
Do
L = InStr(1, Buf, "<style", vbTextCompare)
If L > 0 Then
k = InStr(L + 6, Buf, "</style>", vbTextCompare)
If k > 0 Then
Buf = Left(Buf, L - 1) + Mid(Buf, k + 8)
Else
Buf = Left(Buf, L - 1)
Exit Do
End If
Else
Exit Do
End If
Loop
Do
L = InStr(1, Buf, "<script", vbTextCompare)
If L > 0 Then
k = InStr(L + 7, Buf, "</script>", vbTextCompare)
If k > 0 Then
Buf = Left(Buf, L - 1) + Mid(Buf, k + 9)
Else
Buf = Left(Buf, L - 1)
Exit Do
End If
Else
Exit Do
End If
Loop
Buf = Replace(Buf, "&", "&")
Buf = Replace(Buf, """, Chr(34)) '替换成双引号
Buf = Replace(Buf, "<", "<")
Buf = Replace(Buf, ">", ">")
Buf = Replace(Buf, " ", "")
Buf = Replace(Buf, "<", " <")
Buf = Replace(Buf, ">", "> ")
Buf = Replace(Buf, " ", "")
Buf = Replace(Buf, Chr(26), " ")
Buf = Replace(Buf, Chr(10), " ")
Buf = Replace(Buf, Chr(9), " ")
Buf = Replace(Buf, Chr(13), " ")
Buf = LTrim(Buf)
Buf = RTrim(Buf)
'您可加入其他替换
StrTemp = ""
For i = 1 To Len(Buf)
c = Mid(Buf, i, 1)
Select Case c
Case "<"
If i <> 1 Then
StrTemp = StrTemp & Mid(Buf, j + 1, i - j - 1)
End If
Case ">"
j = i
End Select
Next i
L = Len(StrTemp)
Do
Buf = Replace(StrTemp, " ", " ")
i = Len(Buf)
If i = L Then Exit Do
L = i
StrTemp = Buf
Loop
StrFormat = Buf
End Function
Private Sub Command1_Click()--------------------编程问答--------------------
With CreateObject("InternetExplorer.Application")
.navigate "http://bbs.csdn.net/topics/390471772"
Do While Not .readyState = 4
DoEvents
Loop
Open "d:\某某.txt" For Output As #1
Print #1, .document.innertext
Close #1
End With
End Sub
--------------------编程问答--------------------
Private Sub Command1_Click()
With CreateObject("InternetExplorer.Application")
.Visible = False
.navigate "http://bbs.csdn.net/topics/390471772"
Do While Not .readyState = 4
DoEvents
Loop
Open "d:\某某.txt" For Output As #1
Print #1, .document.All("post-394605125").All.tags("td")(1).innertext
Close #1
.Quit
End With
End Sub
有点错误,Print #1, .document.innertext应该为:
Print #1, .document.body.innertext --------------------编程问答-------------------- 用vb自带的winsock控件也行。发送http字符串命令就获得网页源码流
补充:VB , 网络编程