Printing the html attribute and save into csv

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

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

<!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
/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

const $ = cheerio.load(pm.response.text())
const html = $.parseHTML(responseBody); 
var jqResponseHTML = $(html);
console.log(jqResponseHTML)
console.log($('tr:nth-child(1) > td:nth-child(5) > a'))

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

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) {
  })
})


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.

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

yeah did !! already console.log({rID}\n`, `{pID}\n, ${lnno});
image

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) {
  })
})

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?

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);.

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

Changed the line

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);  
 })

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

1 Like

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

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. :man_shrugging:t3:

did not get this ? sorry

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

reporters: 'cli'

is that the reason! ?
image

Probably, if that’s the request that has the console logs :joy:

Could try including this in the .run object:

insecure: true

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

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.

2 Likes

This worked !!!
image
but csv are like ? seems like need to change back into single line
image

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

2 Likes

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

Now removing the new lines and checking it again

still doesnt looks good the csv console.log({rID}`, `{pID}, ${lnno});
image
and csv is image