vbscript to append text file

What would be the typical vbscript to open an existing .txt file and append the new data? I'm using the below from the tutorial:

Session.Log "Writing data to a file."
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objStoriesFile = objFSO.GetFile( "H:\Export.txt" )
objStoriesFile.Write Session.GetVariable( "FORM_SUBMITTED_TEXT" )
objStoriesFile.Close

vbscript to append text file

Hi,

Generally you'll invoke scripts before a scraping session when you need to initialize objects, files, etc. For example, you might run a script at the very beginning of your scraping session that writes out headers to a CSV file. We don't often write scripts that get executed after a scraping session has run, but it would generally be done when you need to clean objects up. For example, perhaps you're communicating with an external application during the scrape, and need to let it know once the scrape has finished.

Best wishes,

Todd

vbscript to append text file

Apparently the problem was that I had the export script assigned in the scripts section of the Extractor Patterns tab, instead of the Scripts tab. Moving the script assignment fixed both the file saving problems, and the Parameter assignment script (which *was* in the Scripts tab dialog), which wasn't working on the first pass. I'm guessing that the scripts section of the Extractor Patterns dialog is *only* for patten matching scripts? I thought I put it there when following the tutorial...

I see you can also assign scripts at the Scraping Session level (as opposed the sublevel for the Scrapeable File). When would one use this?

vbscript to append text file

Hi,

The error you're getting would most likely occur if you had the file open in another application (e.g., Notepad). That is, the VBScript engine can't write to the file because another application has an exclusive lock on it. You're welcome to try Interpreted Java, though you'll get a similar error if the file is locked by another app. The Interpreted Java code is on the same page as the VBScript example: here.

Kind regards,

Todd

vbscript to append text file

OK, I've tried this:

Session.Log "Writing data to a file."
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set objExportFile = objFSO.OpenTextFile( "ScrapedData.txt", 8, True )
objExportFile.Write Session.GetVariable( "FORM_SUBMITTED_TEXT" )
objExportFile.Close
Set objExportFile = Nothing
Set objFSO = Nothing

but get

Writing data to a file.
Rymut file: An error occurred while processing the script: Export Rymut data
Rymut file: The error message was: Scripting engine failure
Microsoft VBScript runtime error: 2:0
Permission denied

(scode=0x800a0046 wcode=0x0)

in the log.

I did get it to run once after a restart, but the file was empty. I'm also getting inconsistant behavior on the parameter assignment script.

Should I switch to Interpreted Java, and if so, what's the code?

vbscript to append text file

Hi,

I think this is what you're looking for: here.

Kind regards,

Todd Wilson