批量替换1.htm-100.htm的内容

来源:百度知道 编辑:UC知道 时间:2024/05/14 11:50:52
如何实现呢???? 我生成了1.htm到100.htm 100个文件 或者更多
然后我想将里面的某一段 比如
<html><head><title>百度贴吧_vb吧 </title>
将改为
<html><head><title>VB爱好吧 </title>
如何实现呢??
帮帮忙。。。。 没分了
DownloadFile " http://www.baidu.com/s?wd=" + GetaLine(RichTextBox2, i - 1) + "&cl=3", mulu & qianzhui.Text & "" & i & "." + houzhui.Text
Dim S1 As String
Dim d As String
Open mulu & qianzhui.Text & "" & i & "." + houzhui.Text For Input As #2
While Not EOF(2)
Line Input #2, S1
d = d & S1 & vbCrLf
Wend
Close #2
d = Replace(d, "百度", "vb吧")
Open mulu & qianzhui.Text & "" & i & "." + houzhui.Text For Output As #2
Print #2, d
Close #2

生成后1.htm是正常的 但是2.htm却包含了2个页面 也就是2个htm合在一起,这怎么办呢?

这样吧 读写文件建议使用richTextBox来,否则文件多的话用Open语句很慢的..
比如
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 Long

Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function

Sub ReplaceText() '主过程
Dim i as long
for i = 1 to 100
Downloadfile "http://www.baidu.com/s?wd=" + GetaLine(RichTextBox2, i - 1) + "&cl=3", mulu & qianzhui.Text & "" & i & "." + houzhui.Text
RichTextBox1.Loadfile mulu & qianzhui.Text & "" & i & "." + houzhui.Text
Rich