legend_blue legend_blue -4 years ago 236
CSS Question

Get src img with Powershell Where-Object

I have an html sample like this. I want to get img src link. How to get it with using Powershell?

<ul class="filtered similiar">
<li class="one pie lcls">
<div class="productImg">
<a href="/sihirli-kirmizi-at2612">
<img src="https://sample.jpg" width="170" height="238" alt="Kırmızı Gül Çiçek Aranjmanı" title="Kırmızı Gül Çiçek Aranjmanı">
</a>
</div>
</li>

Answer Source

Quite simple example, use this:

$html = '<img src="https://sample.jpg" width="170" height="238" alt="Kırmızı Gül Çiçek Aranjmanı" title="Kırmızı Gül Çiçek Aranjmanı">'

$srcrpattern = '(?i)src="(.*?)"'

$src = ([regex]$srcrpattern ).Matches($html) |  ForEach-Object { $_.Groups[1].Value }

Tested it quickly with your full HTML and it works fine also. Hope that helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download