人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

VBSの質問です
a.html
***********************
<html><body><table>
<tr>
<td>hogegehogehoge</td>
<td>gehogeoj</td>
<td>banana</td>
</tr>
<tr>
<td>hogegehogehoge</td>
<td>gehogeoj</td>
<td>sakana</td>
</tr>
<tr>
<td>hogehogehohoge</td>
<td>hogehogehogehoge</td>
<td>mikan</td>
</tr>
<tr>
<td>hogehogehohoge</td>
<td>hogehogehogehoge</td>
<td>mikan</td>
</tr>
</TABLE></body></html>
***********************
というファイルがあるのですが
これを各<tr></tr>の最後の<td></td>内をファイル名として以下のように
banana.html
***********************
<html><body><table>
<tr>
<td>hogegehogehoge</td>
<td>gehogeoj</td>
<td>banana</td>
</tr>
</TABLE></body></html>
***********************

sakana.html
***********************
<html><body><table>
<tr>
<td>hogegehogehoge</td>
<td>gehogeoj</td>
<td>sakana</td>
</tr>
</TABLE></body></html>
***********************

mikan.html
***********************
<html><body><table>
<tr>
<td>hogehogehohoge</td>
<td>hogehogehogehoge</td>
<td>mikan</td>
</tr>
<tr>
<td>hogehogehohoge</td>
<td>hogehogehogehoge</td>
<td>mikan</td>
</tr>
</TABLE></body></html>
***********************
のように分けたいんですが
どのようなスクリプトを組めばいいでしょうか?
表の列数は行数は変化します

●質問者: takanii
●カテゴリ:コンピュータ
○ 状態 :終了
└ 回答数 : 1/1件

▽最新の回答へ

1 ● きゃづみぃ
●500ポイント ベストアンサー
Dim objFile  ' 対象ファイル
Dim objFile2 ' 出力ファイル
Dim objFSO ' ファイルシステムオブジェクト
Dim k
Dim tb()
Dim tb2()

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("a.html")
k=0
Do Until objFile.AtEndOfLine = True
strText = objFile.ReadLine
k=k+1
redim Preserve tb(k)
tb(k)=strText
if instr(strText,"</tr>") > 0 then
a=instr(tb(k-1),"<td>")
b=instr(a+1,tb(k-1),"</td>")
c = mid(tb(k-1),a+4,b-5)
Set objFile2 = objFSO.CreateTextFile(c & ".html")
d=1
if tb(1)="<html><body><table>" then d=2
objFile2.WriteLine("<html><body><table>")
for a=d to k
objFile2.WriteLine ( tb(a) )
next
objFile2.WriteLine("</TABLE></body></html>")
objFile2.Close
k=0
redim tb(1)
end if

Loop
objFile.Close


>各<tr></tr>の最後の<td></td>内をファイル名
この場合、

<tr>
<td>hogehogehohoge</td>
<td>hogehogehogehoge</td>
<td>mikan</td>
</tr>
<tr>
<td>hogehogehohoge</td>
<td>hogehogehogehoge</td>
<td>mikan</td>
</tr>

だと それぞれ 二つに 分かれてしまうと思われますが、
これが ひとつになる条件は 何があるのでしょうか?


takaniiさんのコメント
<td>mikan</td> これです

takaniiさんのコメント
mikan これです

きゃづみぃさんのコメント
>|| <td>mikan</td> が 二つありますよね。 もし、同じものがある場合は、連結させる ということですか。 ||<

きゃづみぃさんのコメント
>|vb| Dim objFile ' 対象ファイル Dim objFile2 ' 出力ファイル Dim objFSO ' ファイルシステムオブジェクト Dim k Dim tb() Dim tb2() Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("a.html") k=0 Do Until objFile.AtEndOfLine = True strText = objFile.ReadLine k=k+1 redim Preserve tb(k) tb(k)=strText if instr(strText,"</tr>") > 0 then a=instr(tb(k-1),"<td>") b=instr(a+1,tb(k-1),"</td>") c = mid(tb(k-1),a+4,b-5) if objFSO.FileExists(c & ".html") then '既存ファイルがあれば追加する。 Set objFile2 = objFSO.OpenTextFile(c & ".html") kk = 0 Do Until objFile2.AtEndOfLine = True strText = objFile2.ReadLine kk=kk+1 redim Preserve tb2(kk) tb2(kk) = strText Loop objFile2.Close Set objFile2 = objFSO.OpenTextFile(c & ".html",2) for e=1 to kk -1 objFile2.WriteLine ( tb2(e) ) next for a=d to k objFile2.WriteLine ( tb(a) ) next objFile2.WriteLine("</TABLE></body></html>") else Set objFile2 = objFSO.CreateTextFile(c & ".html") d=1 if tb(1)="<html><body><table>" then d=2 objFile2.WriteLine("<html><body><table>") for a=d to k objFile2.WriteLine ( tb(a) ) next objFile2.WriteLine("</TABLE></body></html>") objFile2.Close end if k=0 redim tb(1) end if Loop objFile.Close ||< 質問にあるように出力されるようにしました。

takaniiさんのコメント
大変有り難うございました! 助かりました!

関連質問

●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ