此代码在我的桌面上创建一个新CSV。它从源CSV中提取链接。源CSV是一列URL链接。在输出新CSV中,它会创建一个列 标题为Column_1_Name(我希望它在第1行),然后在下一行,它将提取的文本放在URL scrape中。问题是,在CSV(第3行)的下一行,它再次重复列标题(Column_1_Name),然后重复下一个提取的数据。然后再次Column_1_Name标题(第5行),然后提取数据。等等。
我需要知道如何将Column_1_Name标头放入新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}}
答案 0 :(得分:0)
以下解决方法对您有所帮助:
'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}}