1
htmlイメージタグを含む1000以上のデータベースエントリがあります。htmlイメージタグ内の属性を置き換えます
問題は、 'src'属性の90%が単なるプレースホルダです。私はそれらのプレースホルダーのすべてを適切な、実際の情報源に置き換える必要があります。
<p>A monster rushes at you!</p>
Monster:<p><img id="d8fh4-gfkj3" src="(image_placeholder)" /></p>
<br />
Treasure: <p><img id="x23zo-115a9" src="(image_placeholder)" /></p>
Please select your action below:
</br />
上記イメージタグ内のIDを使用して、「d8fh4-gfkj3」&「x23zo-115a9:一般的なデータベース・エントリは次のようになり
(イメージタグの量は、エントリからのエントリに変えます) '、私はそれらの画像のための "本当の"情報源を得るために別の関数を問い合わせることができます。
だから私はHtmlAgilityPackを使用してみましたし、この思い付いた(下):
Dim doc As New HtmlDocument()
doc.LoadHtml(encounterText)
For Each imgTag As HtmlNode In doc.DocumentNode.SelectNodes("//img")
'get the ID
Dim imgId As HtmlAttribute = imgTag.Attributes("id")
Dim imageId As String = imgId.Value
'get the new/real path
Dim newPath = getMediaPath(imageId)
Dim imgSrc As HtmlAttribute = imgTag.Attributes("src")
'check to see if the <img> tag "src" attribute has a placeholder
If imgSrc.Value.Contains("(image_placeholder)") Then
'replace old image src attribute with 'src=newPath'
End If
Next
しかし、私は実際には新しい値で古い値を交換する方法を見つけ出すことはできません。
HtmlAgilityPackでこれを行う方法はありますか?
ありがとうございます!