powershell - Using wildcards to download a file with Invoke-WebRequest -


i have url in there 6 digits changing daily.

sample website: https://www.ecb.europa.eu/paym/coll/assets/html/dla/ea_mid/ea_csv_160126.csv

this part changes: 160126

i don't know correct syntax form of pseudo code:

$url = "https://www.ecb.europa.eu/paym/coll/assets /html/dla/ea_mid/ea_csv_" + [0-9][0-9][0-9][0-9][0-9][0-9]+ ".csv" 

how can write string?

to answer comments, use download file folder, this:

"https://www.ecb.europa.eu/paym/coll/assets/html/dla/ea_mid/ea_csv_" + [0-9]+[0-9]+[0-9]+[0-9]+[0-9]+[0-9] +".csv" $output = "c:\myfolder\somesubfolder\scriptdownload" $start_time = get-date  invoke-webrequest -uri $url -outfile $output   write-output "time taken: $((get-date).subtract($start_time).seconds) second(s)"   

what asking cannot done. there better, more reliable ways same result looking for.

i'm martin. found download page did. better way link. not best way information start in right direction.

note slow hell. because of invoke-webrequest

$start_time = get-date $output = "c:\myfolder\somesubfolder\scriptdownload" # browse page hosting csv file. $request = invoke-webrequest "https://www.ecb.europa.eu/paym/coll/assets/html/list-mid.en.html" # locate uncompressed csv file name page $filename = $request.parsedhtml.getelementsbytagname("a") | where-object{$_.nameprop -match "^ea_csv_\d{6}\.csv$"} | select -expandproperty nameprop $fileurl = "https://www.ecb.europa.eu/paym/coll/assets/html/dla/ea_mid/$filename"  # file hosted today. invoke-webrequest -uri $fileurl -outfile "$output\$filename"  write-output "time taken: $((get-date).subtract($start_time).seconds) second(s)"   

the way find right file name ^ea_csv_\d{6}\.csv$ matches name "ea_csv_[6 digits].csv".


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -