お世話になります。
現在、phpを使用しており正規表現またはDOMで以下のHTMLのようなデータから
一定の情報を正規表現又はDOMを使用することにより、抽出する事を試みております。
*正規表現により取得するデータは既に既にこちらのクライアント側にあるHTMLファイルであり、
取得先のサーバーへの負担等の問題は今回はご配慮頂かなくとも問題ございません。
【目的】
例えばですが、下記のHTMLをレンダリングした結果、以下のような構成になっております。
(A) aaaaa
(B) bbbbb,bbbbb
(C) ccccccc
これを例えば(A)について、以下のようなデータの抽出の方法を模索しています。
<p style="margin-left: 14px; text-align: justify; text-justify: inter-ideograph"> </p> <p style="margin-left: 36px; text-align: justify; text-justify: inter-ideograph"> <span style="font-family: 'MS Mincho'; font-size: 12px">(A)</span> </p> <p style="margin-left: 36px; text-align: justify; text-justify: inter-ideograph; text-indent: 14px"> <span style="font-family: 'MS Mincho'; font-size: 12px">aaaaa</span> </p>つまり(A)のブロックについて、次の(B)のブロックの直前まで、タグを含めてブロック毎することが趣旨になります。
【状況】
1.ここで(A)(B)(C)の前後のタグは特に法則ないです。
例えば、(A)の前にある以下のタグも必ず他のタグでもそうであるわけではありません。
2.今回は抜粋として(A)(B)(C)のブロックをお示ししましたが、実際には(A)(C)や(A)(D)(E)といったパターンもあり
これらのパターンを含めてブロックを取得する方法を一般化しようとしております。
3.全てに共通することは(A)(B)....(Z)について、これらがどのようなものであるかは把握されております。
例えば、(北海道)札幌市 (兵庫県)神戸市のようにイメージして頂ければと思います。
【質問】
・上記の通りタグやタグの属性法則がないため、DOMをうまく利用することができないのですが、
このようなケースでDOMで目的にあるようなブロックを取得することができるのでしょうか?
nodeValue((A)とかの内容)は分かっているの、そこからアプローチができるかとも思ったのですが、
試行錯誤しても目的を達成できませんでした。
・正規表現でやる場合に様々なケースに対応する必要があるため、難しいとは思うのですが(A)をキーにして
そのブロックを取得するのは可能でしょうか?また、そもそもこのようなケースの場合、DOMや正規表現ではない
方法が推奨される場合には、なにかアイデアがあればご助言を頂ければ幸いです。
HTML
1<p style="margin-left: 14px; text-align: justify; text-justify: inter-ideograph"> </p> 2<p style="margin-left: 36px; text-align: justify; text-justify: inter-ideograph"> 3<span style="font-family: 'MS Mincho'; font-size: 12px">(A)</span> 4</p> 5<p style="margin-left: 36px; text-align: justify; text-justify: inter-ideograph; text-indent: 14px"> 6<span style="font-family: 'MS Mincho'; font-size: 12px">aaaaa</span> 7</p> 8<p style="text-align: justify; text-justify: inter-ideograph"> </p> 9<p style="margin-left: 36px; text-align: justify; text-justify: inter-ideograph"> 10<span style="font-family: 'MS Mincho'; font-size: 12px">(B)</span> 11</p> 12<div style="margin-left: 24px"> 13<table style="table-layout: fixed; width: 624px" cellpadding="0" cellspacing="0"> 14<colgroup> 15<col style="width: 156px"/> 16<col style="width: 468px"/> 17</colgroup> 18<tbody> 19<tr> 20<td style="width: 155px; border-left: 1px solid transparent; border-right: 1px solid transparent"/> 21<td style="border-left: 1px solid transparent; border-right: 1px solid transparent"/> 22</tr> 23<tr style="min-height: 1.33333337306976px"> 24<td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: top"> 25<p style="margin-left: 24px; margin-right: 4px; text-align: justify; text-justify: inter-ideograph; text-indent: -18px"> 26<span style="font-family: 'MS Mincho'; font-size: 12px">bbbbb</span> 27</p> 28</td> 29<td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: top"> 30<p style="margin-left: 24px; margin-right: 4px; text-align: justify; text-justify: inter-ideograph"> 31<span style="font-family: 'MS Mincho'; font-size: 12px">bbbb</span> 32</p> 33<p style="margin-left: 24px; margin-right: 4px; text-align: justify; text-justify: inter-ideograph"> 34<span style="font-family: 'MS Mincho'; font-size: 12px">bbbbbb</span> 35</p> 36</td> 37</tr> 38</tbody> 39</table> 40</div> 41<p style="text-align: justify; text-justify: inter-ideograph"> </p> 42<p style="margin-left: 36px; text-align: justify; text-justify: inter-ideograph"> 43<span style="font-family: 'MS Mincho'; font-size: 12px">(C)</span> 44</p> 45<p style="margin-left: 60.6666679382324px; text-align: justify; text-justify: inter-ideograph"> 46<span style="font-family: 'MS Mincho'; font-size: 12px">ccccccc</span> 47</p> 48
回答2件
あなたの回答
tips
プレビュー