Solution to my Permission Denied problem
I am a new user of screen-scraper. After the initial learning curve, everything was working except I was getting a permission denied error in my Write To File script when looping through multiple scrapes.
I checked everything to do with the file system with no luck. Then when I did a large run I noticed that the error did not occur all of the time. Time was the answer. Here is my final script with a delay coded to eliminate the error.
Also on the website I was scraping, I found that one of the fields, SCHOOL_CITY, was not presented consistantly. So I created two different sub-extractor patterns and the error handling I put in for the delay also works to choose which ever version occurs on the page.
Notice that the vbTab is written separately so that when there is no value for an item, I still get the tab as a delimiter which I need when I import the file into a database.
Hope this helps someone.
' Generate objects to write data to a file.
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
on error resume next
Set objDVDFile = objFSO.OpenTextFile( "C:\data\test11.txt", 8, True )
while err.number <> 0
Wscript.sleep 100
err.clear
Set objDVDFile = objFSO.OpenTextFile( "C:\data\test11.txt", 8, True )
wend
' Write out the data to the file.
objDVDFile.Write DataRecord.Get( "SCHOOL_NAME" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_ADDRESS" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_CITY" )
objDVDFile.Write DataRecord.Get( "SCHOOL_CITY1" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_PHONE" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_FAX" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_WEBSITE" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_MASCOT" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_COACH" )
objDVDFile.Write vbTab
objDVDFile.Write DataRecord.Get( "SCHOOL_CEMAIL" )
objDVDFile.Write vbCrLf
' Close the file and clean up.
objDVDFile.Close
Set objFSO = Nothing
Set objDVDFile = Nothing
Solution to my Permission Denied problem
Thanks a bunch! I'll give it a try, and let you know how I make out.
It's really awesome because I posted a question about this yesterday in a separate thread, and I think you may be the answer to my prayers (So to speak!) :lol:
Thanks again,
McFly
Solution to my Permission Denied problem
You are right this replaces the "Write Data To File" script. It should be added under the Extractor Patterns tab, below the Extractor Patterns where it says "Add Script". The "When to Run" should be "After each pattern application".
I am using the method where I do one Extractor Pattern which pulls out the section of the html that I want to work with and I use the special ~@DATARECORD@~ variable in that Extractor Pattern to identify that html.
Then I use multiple Sub-Extractor Patterns to isolate one or more variables and use the SCHOOL_whatever variables. That's why in the code I can reference
objDVDFile.Write DataRecord.Get( "SCHOOL_NAME" )
because I am using ~@DATARECORD@~
Solution to my Permission Denied problem
Hey Hoosier
Thanks for writing this post :) However, I tried it out and can't get it to output anything. :?
It runs fine with no errors, but no text file is even created. I am assuming that this file is a replacement for the stock "Write Data to a File" Script and that it get initiated from the scrapeable file "after file is scraped"
What am I missing here? I'm still a little confused about the difference between "DataRecord.Get()" and "Session.GetVariable()" so perhaps this is where my error lies.
Please help if you're able! :oops: I appreciate your time.
Thanks,
Mcfly