JavaScript関数から文字列を抽出する

JavaScript関数から文字列を抽出する

次のJavaScript関数を含む複数のHTMLファイルがあります。

<script type='text/javascript'>eval(function(...............
..............................
781a802d711afb9fe305d5b2e6|nlgphp5ee35huxvkc5xui4xl|gr6weglhvfovda4zodalt7j7glkt5ua|hojehp5ee35huxvkc5xui4xlugr6weglh|vfovl443odalt7klrfbtu4q|mystring123|data|new'.split('|')))
</script>
.......................
<div class="description">mytitle123</div>

|と|data|newの間の部分(この場合は「mystring123」)とタイトル「mytitle123」を抽出したいと思います。最初の文字列は常にevalにあり、| data |で終わります。区切り文字の前の英数字文字列が変更されます。

ベストアンサー1

XML / HTML文書は適切なパーサーツールを使用して処理する必要があります。

xmllint方法(sedすべてのラベル本文テキストで検索/置換をサポート<script>):

$ xmllint --html --xpath '//script/text()' input.html | sed -En 's/.*\|([^|]+)\|data\|new.*/\1/p'
mystring123

$ xmllint --html --xpath '//div[@class="description"]/text()' input.html
mytitle123

おすすめ記事