Reading in from Pipe delimited text file as oposed to CSV
When trying to read in from a pipe (|) delimited text file the scraper can't understand the value delimiter and will only work with a comma separator. Any idea why this is? I have tried to change the file encoding also the character set on the scrape file. Here's my read in fail:
import java.io.*;
////////////////////////////////////////////
session.setVariable("INPUT_FILE", "D:/xxxxx.txt");
////////////////////////////////////////////
BufferedReader buffer = new BufferedReader(new FileReader(session.getVariable("INPUT_FILE")));
String line = "";
while (( line = buffer.readLine()) != null )
{
String[] lineParts = line.split("|");
session.setVariable("SKU", lineParts[1]);
session.setVariable("Brand", lineParts[0]);
session.log( "column 1 is:" + session.getv("Brand") );
session.log( "column 2 is:" + session.getv("SKU") );
// Output to the log
session.log("Now scraping Product SKU: " + session.getVariable("SKU") );
if (session.getVariable("SKU") != "Product Name")
{
session.scrapeFile("search");
session.pause(7000);
}}
buffer.close();
The pipe is a special
The pipe is a special character that you need to escape
////////////////////////////////////////////
session.setVariable("INPUT_FILE", "D:/xxxxx.txt");
////////////////////////////////////////////
BufferedReader buffer = new BufferedReader(new FileReader(session.getVariable("INPUT_FILE")));
String line = "";
while (( line = buffer.readLine()) != null )
{
String[] lineParts = line.split("\\|");
session.setVariable("SKU", lineParts[1]);
session.setVariable("Brand", lineParts[0]);
session.log( "column 1 is:" + session.getv("Brand") );
session.log( "column 2 is:" + session.getv("SKU") );
// Output to the log
session.log("Now scraping Product SKU: " + session.getVariable("SKU") );
if (session.getVariable("SKU") != "Product Name")
{
session.scrapeFile("search");
session.pause(7000);
}
}
buffer.close();