# Printing the html attribute and save into csv

**URL:** <https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027>\
**Category:** Help Hub\
**Tags:** parsing-html, console, csv, cheerio, newman-project\
**Created:** [March 4, 2021, 7:07pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027 "2021-03-04T19:07:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 4, 2021, 7:07pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/1 "2021-03-04T19:07:41Z")

</div>

1 Call the api  
2. Extract output only href tags with submit linkname  
Or  
Can capture the id value , requestid value and ln value and save into csv  
note: out have 50-60 submit links  
`id=24808&requestId=1614881979066&ln=1000043845`

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 4, 2021, 7:24pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/2 "2021-03-04T19:24:06Z")

</div>

lets say url is `/appstest/RunUpdate?id=26216&requestId=1614895894455&ln=1000043845` want to print `id, requestId, ln` values only in console

How to extract all the href links with submit linknames from below html response

```auto
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>appstest Import System: Loans Processed</title>
<link rel="stylesheet" type="text/css" href="/appstest/css-table.css">
<script type="text/javascript" src="/appstest/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/appstest/appstest.js"></script>
</head>
<body>
<table width="100%"><caption>Loans in process queue (Sorted by last modified)</caption>
<thead><tr>
<th scope="col">File Name</th>
<th scope="col">ID Number</th>
<th scope="col">Date Created</th>
<th scope="col">Last Modified</th>
<th scope="col">Request</th>
</tr></thead><tbody>
<tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043845 target=loanDetail>1000043845</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26088&requestId=1614893866191&ln=1000043845 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043833 target=loanDetail>1000043833</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26089&requestId=1614893866191&ln=1000043833 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043832 target=loanDetail>1000043832</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26090&requestId=1614893866191&ln=1000043832 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043831 target=loanDetail>1000043831</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26091&requestId=1614893866191&ln=1000043831 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043845 target=loanDetail>1000043845</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26092&requestId=1614893866191&ln=1000043845 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043833 target=loanDetail>1000043833</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26093&requestId=1614893866191&ln=1000043833 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043832 target=loanDetail>1000043832</a></td><td>2021-03-04 15:37:49.437</td><td>2021-03-04 15:37:49.437</td><td><a href=/appstest/RunUpdate?id=26094&requestId=1614893866191&ln=1000043832 target=_new>Submit</td></tr><tr><td>FILECheckTestLoans.xlsx</td><td><a href=/LoanServicing/GetLoanData?loannumber=1000043831

```

```auto
/html/body/table/tbody/tr[1]/td[5]/a 
...
/html/body/table/tbody/tr[50]/td[5]/a

```

Tried this no help apart from outer html

```auto
const $ = cheerio.load(pm.response.text())
const html = $.parseHTML(responseBody); 
var jqResponseHTML = $(html);
console.log(jqResponseHTML)

```

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 12:34am UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/3 "2021-03-05T00:34:26Z")

</div>

> [@gpub1](#):
>
> ```auto
> /html/body/table/tbody/tr[1]/td[5]/a 
> ...
> /html/body/table/tbody/tr[50]/td[5]/a
> 
> ```
> 
> Tried this no help apart from outer html
> 
> ```auto
> const $ = cheerio.load(pm.response.text())
> const html = $.parseHTML(responseBody); 
> var jqResponseHTML = $(html);
> console.log(jqResponseHTML)
> 
> ```

```auto
console.log($('tr:nth-child(1) > td:nth-child(5) > a'))

```

I’m unable to print console logs into csv using library

```auto
const newman = require('newman'),
      fs = require('fs')

newman.run({
   collection: 'https://www.getpostman.com/collections/ccd10ada71bc5d379ad6', //updated one both are same though
   //environment: 'TestEnv_TPO.postman_environment.json',
   //collection: 'QueueTest_Batch.postman_collection.json',
   //iterationCount: 1 //chage to 1 for All range.
}).on('console', function (error, args) {
      fs.appendFileSync('QUESUESERA.csv', args.messages, function (error) {
  })
})

```

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/b/bf7c06dcf550bf1dc498fdab8a615a348bb42171.png)  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/d/3d8e8113b41812630bc6211c44c04567a06cc05f.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 5:37pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/4 "2021-03-05T17:37:11Z")

</div>

```auto
const newman = require('newman'),
      fs = require('fs')

newman.run({
   collection: 'collection.json',
}).on('console', function (err, args) {
  fs.appendFileSync('messages.csv', args.messages);
})

```

Something basic like that should work - You would need to add a newline character in your `console.log` statement though.

```auto
console.log(`${rID},${pID},${lnno}\n`);

```

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 5:40pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/5 "2021-03-05T17:40:05Z")

</div>

yeah did !! already `console.log(`${rID}\n`, `${pID}\n`, `${lnno}`);`  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/6/c6625ae05cb2310fef531f6e9bec1a0dc2ed1193.png)

```auto
const newman = require('newman'),
      fs = require('fs')

newman.run({
   //collection: 'https://www.getpostman.com/collections/ccd10ada71bc5d379ad6', //updated one both are same though
   //environment: 'TestEnv_TPO.postman_environment.json',
   collection: 'QueueTest_Batch.postman_collection.json',
   //iterationCount: 1 //chage to 1 for All range.
}).on('console', function (error, args) {
      fs.appendFileSync('QUESUESERA.csv', args.messages, function (error) {
  })
})

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 5:44pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/6 "2021-03-05T17:44:50Z")

</div>

I don’t understand what you’re doing - Are you trying to use Newman to create the csv file or just printing things to the console?

Do you need a newline after each item? That wouldn’t really create the csv in the way that would make each line an iteration.

What is that line doing?

```auto
fs.appendFileSync('QUESUESERA.csv', args.messages, function (error) {
  })

```

The syntax for that is not correct, it should be just `fs.appendFileSync('QUESUESERA.csv', args.messages);`.

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 5:54pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/7 "2021-03-05T17:54:06Z")

</div>

> [@danny-dainton](#):
>
> I don’t understand what you’re doing - Are you trying to use Newman to create the csv file or just printing things to the console?

**`Correction from postman printing on console`** and expected csv to be like  
`29407 1614961869293 1000043833`

Changed the line

```auto
const newman = require('newman'),
      fs = require('fs')

newman.run({
   collection: 'QueueTest_Batch.postman_collection.json',
}).on('console', function (error, args) {
    fs.appendFileSync('QUESUESERA.csv', args.messages);  
 })

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 5:56pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/8 "2021-03-05T17:56:08Z")

</div>

What is not working when you run that command in Newman?

What does the file look like?

Are you updating the collection each time you make a change?

Here’s what it creates for me:

![image](https://us1.discourse-cdn.com/getpostman/original/2X/1/19cfb497df537dca3cd0d936a29675eafd273fd3.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/7/70e8a9b1c7573390b57a0afd3bbe5f0aaeac23b4.png)

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 6:02pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/9 "2021-03-05T18:02:35Z")

</div>

> [@danny-dainton](#):
>
> What is not working when you run that command in Newman?

I am running on command `node QUEUEListing.js`

csv File is not created

Are you updating the collection each time you make a change?  
Yes every time

but csv file is not getting saved or created, not sure what’s missing ? its not even getting created

![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/b/fb15e452e688eb8e4c0e09a8dc55ae69cd9aa3a9.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 6:08pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/10 "2021-03-05T18:08:19Z")

</div>

Is it printing the logs when you add the CLI reporter?

I don’t really know what to tell you, the Newman command runs and creates the file for me. 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 6:09pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/11 "2021-03-05T18:09:36Z")

</div>

> [@danny-dainton](#):
>
> Is it printing the logs when you add the CLI reporter?

did not get this ? sorry

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 6:13pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/12 "2021-03-05T18:13:30Z")

</div>

Use the CLI reporter to print the whole run to the terminal.

```auto
reporters: 'cli'

```

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 6:40pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/13 "2021-03-05T18:40:05Z")

</div>

> [@danny-dainton](#):
>
> CLI reporter to print the whole run to the terminal.

is that the reason! ?  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/9/7980752026409a65f3127b5e5e698bdfc81764b0.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 7:00pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/14 "2021-03-05T19:00:16Z")

</div>

Probably, if that’s the request that has the console logs 😂

Could try including this in the `.run` object:

```auto
insecure: true

```

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 7:05pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/15 "2021-03-05T19:05:42Z")

</div>

> [@danny-dainton](#):
>
> Probably, if that’s the request that has the console logs

Yeah cause of some production issues we need to get data from this request from api and yes that’s the api for test env, and then only we will move this for PRod env check

Sorry not understanding this, Could try including this in the `.run` object:  
with this command  
`newman run https://www.getpostman.com/collections/ccd10ada71bc5d379ad6 -r csv`

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/4/7/4760a9c2400f6754ae931d765e469cde0a5c2c55.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 7:18pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/16 "2021-03-05T19:18:40Z")

</div>

```auto
const newman = require('newman'),
      fs = require('fs')

newman.run({
   collection: 'QueueTest_Batch.postman_collection.json',
   insecure: true
}).on('console', function (error, args) {
    fs.appendFileSync('QUESUESERA.csv', args.messages);  
 })

```

A basic understanding of what this is and how you can use different options within it could really help you out here.

> **[postmanlabs/newman - Using Newman as a Library](https://github.com/postmanlabs/newman#using-newman-as-a-library)**
>
> Newman is a command-line collection runner for Postman

> **[postmanlabs/newman - newman.run(options: object , callback: function) =\> run: EventEmitter](https://github.com/postmanlabs/newman#newmanrunoptions-object--callback-function--run-eventemitter)**
>
> Newman is a command-line collection runner for Postman

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 7:22pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/17 "2021-03-05T19:22:38Z")

</div>

> [@danny-dainton](#):
>
> `insecure: true`

This worked !!!  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/0/801f7895f2cc9e01a5791c709597fea3e32d3461.png)  
but csv are like ? seems like need to change back into single line  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/0/00e4990e3fd8d80c3893585fcf0307fa9862dc5f.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 5, 2021, 7:30pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/18 "2021-03-05T19:30:45Z")

</div>

I mentioned that a long time ago…

> Do you need a newline after each item? That wouldn’t really create the csv in the way that would make each line an iteration

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 7:32pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/19 "2021-03-05T19:32:59Z")

</div>

> [@danny-dainton](#):
>
> I mentioned that a long time ago…

LOL, if thats on my query then owe you an icecream 😃

Now removing the new lines and checking it again

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [March 5, 2021, 7:43pm UTC](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027/20 "2021-03-05T19:43:13Z")

</div>

still doesnt looks good the csv `console.log(`${rID}`, `${pID}`, `${lnno}`);`  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/9/e9ad3cff0a83060dbde0361398962eb92d55b64f.png)  
and csv is ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/c/fc8f4095b334ff42ad9697c9b930a8766e51a165.png)

[Next page](https://community.postman.com/t/printing-the-html-attribute-and-save-into-csv/21027.md?page=2)
