Invoke-WebRequest gives a single line CSV file

Hello,

I am using the Invoke-WebRequest to extract data from a website that ends with .HTML. The data is stored as a CSV file, however, it is all stored as a single line. I'd like the data to match what is on the website. Below is an example.

ID, Title, Name, Age

1,Mr,Jason,19

2,Mrs,Judy,30

3,Mr,John,42

The data on the CSV file is coming in as ID,Title,Name,Age<BR>,1,Mr,Jason,19<BR>,2,Mrs,Judy,30<BR>,3,Mr,John,42

Any idea why this is happening and how I can get a multiple line CSV file data?

August 21st, 2015 2:31pm

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 2:57pm

Hi Bill,

Thank you for responding back so quickly!!

How do I make this change using the CSV file name only as against calling the individual text in it? I have plenty of data coming in from the HTML file.

August 21st, 2015 3:39pm

How do I make this change using the CSV file name only as against calling the individual text in it? I have plenty of data coming in from the HTML file.

Sorry, but I can't make any sense out of what you are asking.

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 4:20pm

I'm running a PowerShell script that dumps all the data from the HTML file into a CSV file. The data in the CSV file is a single line as I showed above.

Here's the script

Invoke-WebRequest -Uri http://website.com/test.html -OutFile C:\output.csv

How can I edit that above script to give me the data in multiple lines but in the same CSV file?

August 21st, 2015 4:29pm

Try this:

$import = Get-Content 'C:\output.csv'

$import -replace '<BR>,', "`r`n"

ID,Title,Name,Age
1,Mr,Jason,19
2,Mrs,Judy,30
3,Mr,John,42
  • Marked as answer by Darogael 10 hours 1 minutes ago
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 4:47pm

That worked!

Thanks Viktor and Bill

August 21st, 2015 5:11pm

Try this:

$import = Get-Content 'C:\output.csv'

$import -replace '<BR>,', "`r`n"

ID,Title,Name,Age
1,Mr,Jason,19
2,Mrs,Judy,30
3,Mr,John,42
  • Marked as answer by Darogael Friday, August 21, 2015 9:07 PM
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 8:43pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics