PRODUCT |

|

|
|

|
|
|
|
|
FAQ |
|

|
|
|
|
|
|
LEARN SCRIPTING |
|

|
|
|
|
|
|
|
|
|
|
SAMPLE SCRIPTS |
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
HELP / DOCUMENTATION |
|

|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
Help Page - SS_SearchURL
( Some help pages may not display correctly in html because those help pages may have sample code in them, part of which may be mis-interpreted as html tags.
All help pages, including this help page, are available in biterScripting with the help command. )
|
|
Sample Script
SS_SearchURL
Purpose
Searches a URL for a specified Search String or Regular Expression.
Source Code
#####################################################################
# SCRIPT: SS_SearchURL
#
# This script extracts parts of a URL that contain a specified string
# or regular expression. 5 lines before and after are extracted. This
# number 5 is arbitrary. You can refine that part of the script to
# suit your requirements.
#
# The URL is assigned using FVA (Forward Variable Assignment)
# for str variable $URL. The value of $URL is of form
# "http://www.xxx.yyy" or "http://www.xxx.yyy/zzz...qqq/pppp.html
#
# The search string or regular expression is passed using FVA for
# str variable $search_sting. Note that even if this variable is called
# search_string, you can pass a regular expression though it.
#
# This script can be stored and edited as necessary, in a text file
# called SS_SearchURL.txt . The script can then be called as
#
# script SS_SearchURL.txt URL("http://www.abc.def/.../page.html") search_string("Computer Training")
#
#####################################################################
var str URL # The URL to search
var str search_string # String or Regular Expression to search for
var str content # Collects the contents of the URL here.
# $content is progressively cut down as each new instance
# of search_string is found.
repro $URL >$content
# The <search_string> to all string editors needs to be passed
# in the form of "^<search_string>^]", so we will create a
# dynamic str argument.
var str stex_arg
set $stex_arg = "^" + $search_string + "^" + "]"
# We will collect content upto the first instance into a pre string.
var str preStr
stex -c -r $stex_arg $content > $preStr
# If $preStr is empty, the <search_string> is not in $content.
while ( $preStr <> "" )
do
# preStr now has the part up to (and including) <search_string>. We
# will extract 5 lines before that. We want the last 5 lines from $preStr.
var int lines
set $lines = { len -e $preStr }
# If $lines is 100, as an example, we want to pass argument "[95" to the next lex command.
set $lines = $lines - 5
# If $lines is a number less than 1, the lex command will complain. This would happen
# if the <search_string> is found within the first 5 lines of the URL.
if ($lines < 1)
set $lines = 1
endif
# Create the dynamic argument for the lex command in a str variable.
var str lex_arg
set $lex_arg="["+makestr(int($lines))
lex -e $lex_arg $preStr # The 5 lines before (and including) <search_string> will be written to screen.
# The remaining $content now starts after the <search_string>. We will collect
# the next 5 lines.
lex "5]" $content # The 5 lines after <search_string> will be written to screen.
# $content is already stripped of the portion upto 5 lines after this instance
# of <search_string>. We will now find the next instance, and continue the while loop
# until there are no more instance left in $content.
stex -c -r $stex_arg $content > $preStr
done
|
|
© 2008-2013, biterScripting.com. All rights reserved.
biterScripting, biterScript, biterBrowser, biterMobile, biterScripting.com, FVA (Forward Variable Assignment) are trademarks of biterScripting.com. Is it biterScripting-compatible ? is a service mark of biterScripting.com.
Explorer, Unix, Windows are trademarks, service marks or other forms of intellectual property of their respective owners.
|
|