停止脚本在 CSV 列 header 上循环?

Stop script from looping on CSV column header?

此代码在我的桌面上创建了一个新的 CSV。它从源 CSV 中提取链接。源 CSV 是一列 URL 个链接。在输出的新 CSV 中,它创建了一列 标题为 Column_1_Name(正如我希望它在第 1 行),然后在下一行放置从 URL 抓取中提取的文本。问题是,在 CSV 的下一行(第 3 行)中,它再次重复列 header (Column_1_Name),然后是下一个提取的数据。然后再次 Column_1_Name header(第 5 行),然后提取数据。等等

我需要知道如何将 Column_1_Name header 放入新的 CSV 中,然后让代码继续执行数据提取循环,直到它已完成源 CSV 中所需的 URL 秒数。

VERSION BUILD=844 RECORDER=CR

'Setting the column header in our output CSV File
URL GOTO=www.google.com
ADD !EXTRACT <SP>Column_1_Name<SP>
SAVEAS TYPE=EXTRACT FOLDER=/Users/preston/Desktop/ FILE=New_File_Name{{!NOW:mm-dd-yy}}


SET !DATASOURCE /Users/preston/Desktop/SourceCSV_File.csv
SET !EXTRACT_TEST_POPUP NO
SET !DATASOURCE_COLUMNS 2
'Start at line 2 in the file (below)
SET !LOOP 2
'Increase the current position in the file with each loop
SET !DATASOURCE_LINE {{!LOOP}} 


'Extracting Data into our New_File_Name.csv from our SourceCSV_File.csv, the source file contains a column header, and rows of URL links
URL GOTO={{!COL1}}
TAG POS=1 TYPE=TD ATTR=CLASS:random-class-name EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=/Users/preston/Desktop/ FILE=New_File_Name{{!NOW:mm-dd-yy}}

以下解决方法可能对您有所帮助:

'Start at line 2 in the file (below)
SET !LOOP 2
SET firstFolder "/Users/preston/Desktop/"

'Setting the column header in our output CSV File
URL GOTO=www.google.com
SET !EXTRACT <SP>Column_1_Name<SP>
SET firstFolder EVAL("({{!LOOP}} == 2) ? '{{firstFolder}}' : '';")
SET !ERRORIGNORE YES
SAVEAS TYPE=EXTRACT FOLDER={{firstFolder}} FILE=New_File_Name{{!NOW:mm-dd-yy}}
SET !ERRORIGNORE NO
SET !EXTRACT NULL

SET !DATASOURCE /Users/preston/Desktop/SourceCSV_File.csv
SET !DATASOURCE_COLUMNS 2
'Increase the current position in the file with each loop
SET !DATASOURCE_LINE {{!LOOP}} 

'Extracting Data into our New_File_Name.csv from our SourceCSV_File.csv, the source file contains a column header, and rows of URL links
URL GOTO={{!COL1}}
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=TD ATTR=CLASS:random-class-name EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=/Users/preston/Desktop/ FILE=New_File_Name{{!NOW:mm-dd-yy}}