Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Download JPG from URL parsed form Web Page parsed from CSV

$
0
0
$csv = Import-Csv -Path "c:\temp\source.csv"
foreach($entry in $csv) {
    $url = ("http:" + ((Invoke-WebRequest –Uri ‘https://www.website.com/webpage.php’ + $_.'vendor part number').Links |`
	Where-Object {$_.href -like “*300*”} |`
	Where-Object {$_.innerHTML -eq “Enlarge"}).href)
   } 

Hi.

With your help, you can end my days frustration. The script above goes to a webpage, list the .links parts and strips out a particular href link based on the field "$_."Vandor Part Number" but only when I manually type in the actaul vendor part number. With this example above, the error is to say that a '+' cannot exist alongside 'invoke-webrequest'

The Where-Object lines narrow out the one line I want form heach web page which then arrives in the form:

http://webiste.com/images/image.jpg

I would like to download this jpg for each part number gleened form each row of the csv file.

I upgraded to Powershell 3.0 today to take advantage of the new WebClinet as such:

$clnt = new-object System.Net.WebClient
$file = "c:\temp\images\" + $_."vendor part number"
$clnt.DownloadFile($url,$file)

The hope is to have a script that reads each row of the CSV, assembles the URL value correctly to retrieve the jpg URL then save that JPG file in a defined location by the name of the variable form teh csv file.

The first problem I cannot seem to solve is the $url is not formed, I get the url without the variable added to the end. Obviously, that fails, so everythign else does, however, when I enter the url manually, it works, just once. I guess this means I have a bad loop and can't parse right.

Any help or pointers are appreciated.

Many thanks

Gund


Viewing all articles
Browse latest Browse all 2562


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>