Link to home
Start Free TrialLog in
Avatar of Caiapfas
Caiapfas

asked on

Make a .js script that scans a .csv and makes links for me. 500points

I'm trying to make a .js file that will scan a .csv file and make links
I should define the basic url in the script, then it should scan the .csv file and add the info from column A to the very end of the basic url.

example :
basic url : http://www.mysite.com/test/123/index.asp?columnA <<< it puts column A info here

then takes the info from column B and makes a link on a template after the string <!-- START -->, and enters a return and ads another and another all 5000 of them.
---------------------------
column A
url string

column B
text of the url



Thanks,
Avatar of adg080898
adg080898

What? ColumnA? ColumnB? All 5000?

Ok, maybe I got it: You want to loop through all the records in a CSV file, craft URLs from its content, and post them to the server?

Sounds tricky from javascript. I suppose you could launch a browser window with the crafted url, somehow wait for it to finish loading, close it, and loop. It would be slow.

Is this what you are after?
Avatar of Caiapfas

ASKER

not really a loop
I want it to scan the .csv file and then take the var urlstring= and make urls on a html doc, on my local pc, for me to upload later

steps:
I set the var's
i run the script from a cmd prompt= cscript blahblah.js
it scans the csv file i specify, and makes links on a html template after the string <!--Start--> and closes itself down.




Something like this, but doesn't work
---------------------------

//process venue list
var listFile = fso.OpenTextFile(list, 1);
var head=listFile.ReadLine(); //skip header
WScript.StdOut.WriteLine("Header line: " + head);
while(!listFile.AtEndOfStream) {
  var line=listFile.ReadLine();
  WScript.StdOut.WriteLine("processing line: " + line);
  if(fmtSel==6) {
    //format must be: number, "venuename, venuestate"
    var fields=line.match(/^\s*(\d*)\s*,\s*\"?([^\"]*)\"?$/);
    var VenueID=fields[1];
    var fullVenue=fields[2];    
    fields=fullVenue.split(",",2);            
    var VenueName=fields[0];            
    var VenueState=fields[1];            
  }
  else {
    var fields=line.split(",");   // Comma Delimited
    //var fields=line.split("\t");  // Tabs
    WScript.StdOut.WriteLine("fields#: " + fields.length);
    var VenueID=fields[0];
    var VenueName=fields[1];    
    var VenueState=fields[2];  
Hi, I've been on vacation...
Can you please post (make available for download somewhere) a sample csv file, sample template file and (a section of) sample final output file?
.csv file
---------------
4738      1-800-Pit-Shop.com 300
4      8 Second Thunder
3054      A.S. Roma
1821      AAA All-Star Game
2484      Aarons 312
3542      Aarons 499
3825      ABC Sports International Figure Skating Challenge
2939      Aberdeen Ironbirds
4467      AC Milan
8      ACC Mens Tournament
5139      ACC Womens Tournament
2521      Accenture Match Play Championship
2956      Acura Classic
2073      Advance Auto Parts 250
4727      Advance Auto Parts 500
2401      AFC Championship
2114      Agassi Grand Slam for Children
1495      AHL All-Star Game
3827      AHL All-Star Skills Competition
-------------------------------------------------------


template will be a simple html file, and the script should start adding the links after <!-- Start -->

-------------------------------------------------------

and the output file will be a simple html file with links

<a href="http://www.test.com?0001">link text</a>

So my last question is: is your csv comma separated or not? I don't see commas in you sample csv file. Can we assume it IS comma separated?
tab
oppps sorry comma
ASKER CERTIFIED SOLUTION
Avatar of lbertacco
lbertacco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lbertacco ,

Thank you, Please refer me to the same books you read about jscript to be so good at it. My first love is jscript/javascript as you can tell.
I think I already mentioned this with you :-) I have no js book, just ues the online documentation downloadable from www.microsoft.com