How do I access global variables? They seem to get set automatically and then I cannot delete the code because I cannot delete the variable. I'd also like to be able to access and create them so I can use JavaScript like in Helium 2.
There seems to be a lot of functionality that was in Helium 2 that is not in Helium 3. I really want to use Helium 3 because it uses SQLite and I discontinued Helium 3 because it was getting too difficult to use the outdated Access database. But I can't seem to find what I need when writing the JavaScript. Maybe it's all there and I am missing something. Please let me know if Helium 3 has the same functionality as Helium 2 or if it is a cut down version. Thanks.
Global Variables
Re: Global Variables
Not sure what you mean by not being able to delete them or by them being set automatically. Global variables in this version are just globals. The previous version only allowed text on global variables, so to emulate this on the new version you'd just create a global and replace the placeholder with any text between double quotes. I typically use an extract action to put a list of variables (you can look at the Setup global on any of our templates for an example).
There is no way to directly retrieve these values from JavaScript. Many of the old JavaScript functions have been removed because there's no need for them anymore, since most of that stuff can be done without JavaScript. What you can do now is pass the values to the script. For instance, if you have a global called Variable1 with this code in it:
And then you do this:
It'll print "Hello world" on the log. (Note that instead of using a literal string as a script you can also add the script to Project Explorer -> Scripting -> Scripts and pass it by name with the Script. prefix)
To pass complex data, you can pass objects and lists. For instance, instead of a string, you could put this on Variable1:
And then do this:
The values of the struct can also be retrieved without JavaScript like this:
Here, any action you put on the placeholder and below will have access to the one and two variables.
You may note that the templates I mentioned before use extract instead of struct. This just avoids having to use return as on the code above, but that won't work with Browser.RunScript.
There is no way to directly retrieve these values from JavaScript. Many of the old JavaScript functions have been removed because there's no need for them anymore, since most of that stuff can be done without JavaScript. What you can do now is pass the values to the script. For instance, if you have a global called Variable1 with this code in it:
Code: Select all
"Hello world"
Code: Select all
Browser.RunScript
· "global.log(argument);"
· Variable1
To pass complex data, you can pass objects and lists. For instance, instead of a string, you could put this on Variable1:
Code: Select all
struct
one
"Hello world"
two
12.34
Code: Select all
Browser.RunScript
· "global.log(argument.one + ' ' + argument.two);"
· Variable1
Code: Select all
return
· Variable1
as (one two)
[…]
You may note that the templates I mentioned before use extract instead of struct. This just avoids having to use return as on the code above, but that won't work with Browser.RunScript.
Juan Soldi
The Helium Scraper Team
The Helium Scraper Team
Re: Global Variables
How would I write to a Global to use it as a variable? I am scraping from multiple tabs and would like all the data to go into one table rather than a table for each tab as is automatically created. Only way I can see doing this is writing the scraped data to a variable and then writing all of the variables to a table at once.
Re: Global Variables
You could do something like this:
If you right click an extract action and select Output Result it'll output it as variables by appending the "as ..." line.
But I usually wouldn't use this method because it may make the whole extraction slower and the code harder to maintain. What I'd do is leave the extraction as is, and then right click the output table set and select Join Tables to generate a query that shows all tables as a single one. Note that you can also save the query and extract it into an actual table by putting this in a separate global:
So there's really no need to force the data into a single table during extraction.
Code: Select all
extract
one
Select.Something
two
Select.Something
as (one two)
extract
three
Select.Something
four
Select.Something
as (three four)
extract
one
one
two
two
three
three
four
four
But I usually wouldn't use this method because it may make the whole extraction slower and the code harder to maintain. What I'd do is leave the extraction as is, and then right click the output table set and select Join Tables to generate a query that shows all tables as a single one. Note that you can also save the query and extract it into an actual table by putting this in a separate global:
Code: Select all
Action.Extract
· Query.MyJoinedTables
· "MySingleTable"
Juan Soldi
The Helium Scraper Team
The Helium Scraper Team